mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Merge pull request #5269 from jakobandersen/cpp_5191
C++, prevent nested declarations in functions.
This commit is contained in:
1
CHANGES
1
CHANGES
@@ -200,6 +200,7 @@ Bugs fixed
|
||||
* #5114: sphinx-build: Handle errors on scanning documents
|
||||
* epub: spine has been broken when "self" is listed on toctree (refs: #4611)
|
||||
* #344: autosummary does not understand docstring of module level attributes
|
||||
* #5191: C++, prevent nested declarations in functions to avoid lookup problems.
|
||||
|
||||
Testing
|
||||
--------
|
||||
|
||||
@@ -2085,7 +2085,7 @@ class ASTTrailingTypeSpecName(ASTBase):
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
# type: () -> Any
|
||||
# type: () -> ASTNestedName
|
||||
return self.nestedName
|
||||
|
||||
def get_id(self, version):
|
||||
@@ -2379,7 +2379,7 @@ class ASTDeclSpecs(ASTBase):
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
# type: () -> unicode
|
||||
# type: () -> ASTNestedName
|
||||
return self.trailingTypeSpec.name
|
||||
|
||||
def get_id(self, version):
|
||||
@@ -2487,7 +2487,7 @@ class ASTDeclaratorPtr(ASTBase):
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
# type: () -> unicode
|
||||
# type: () -> ASTNestedName
|
||||
return self.next.name
|
||||
|
||||
@property
|
||||
@@ -2583,7 +2583,7 @@ class ASTDeclaratorRef(ASTBase):
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
# type: () -> unicode
|
||||
# type: () -> ASTNestedName
|
||||
return self.next.name
|
||||
|
||||
@property
|
||||
@@ -2638,7 +2638,7 @@ class ASTDeclaratorParamPack(ASTBase):
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
# type: () -> unicode
|
||||
# type: () -> ASTNestedName
|
||||
return self.next.name
|
||||
|
||||
@property
|
||||
@@ -2702,7 +2702,7 @@ class ASTDeclaratorMemPtr(ASTBase):
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
# type: () -> unicode
|
||||
# type: () -> ASTNestedName
|
||||
return self.next.name
|
||||
|
||||
@property
|
||||
@@ -2798,7 +2798,7 @@ class ASTDeclaratorParen(ASTBase):
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
# type: () -> unicode
|
||||
# type: () -> ASTNestedName
|
||||
return self.inner.name
|
||||
|
||||
@property
|
||||
@@ -2864,7 +2864,7 @@ class ASTDeclaratorNameParamQual(ASTBase):
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
# type: () -> unicode
|
||||
# type: () -> ASTNestedName
|
||||
return self.declId
|
||||
|
||||
@property
|
||||
@@ -2962,9 +2962,8 @@ class ASTType(ASTBase):
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
# type: () -> unicode
|
||||
name = self.decl.name
|
||||
return name
|
||||
# type: () -> ASTNestedName
|
||||
return self.decl.name
|
||||
|
||||
@property
|
||||
def function_params(self):
|
||||
@@ -3054,7 +3053,7 @@ class ASTTypeWithInit(ASTBase):
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
# type: () -> unicode
|
||||
# type: () -> ASTNestedName
|
||||
return self.type.name
|
||||
|
||||
def get_id(self, version, objectType=None, symbol=None):
|
||||
@@ -3122,7 +3121,7 @@ class ASTConcept(ASTBase):
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
# type: () -> unicode
|
||||
# type: () -> ASTNestedName
|
||||
return self.nestedName
|
||||
|
||||
def get_id(self, version, objectType=None, symbol=None):
|
||||
@@ -3326,7 +3325,7 @@ class ASTDeclaration(ASTBase):
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
# type: () -> unicode
|
||||
# type: () -> ASTNestedName
|
||||
return self.declaration.name
|
||||
|
||||
@property
|
||||
@@ -5791,12 +5790,37 @@ class CPPObject(ObjectDescription):
|
||||
# type: (addnodes.desc_signature, Any, Dict) -> None
|
||||
ast.describe_signature(signode, 'lastIsName', self.env, options)
|
||||
|
||||
def run(self):
|
||||
env = self.state.document.settings.env # from ObjectDescription.run
|
||||
if 'cpp:parent_symbol' not in env.temp_data:
|
||||
root = env.domaindata['cpp']['root_symbol']
|
||||
env.temp_data['cpp:parent_symbol'] = root
|
||||
env.ref_context['cpp:parent_key'] = root.get_lookup_key()
|
||||
|
||||
# The lookup keys assume that no nested scopes exists inside overloaded functions.
|
||||
# (see also #5191)
|
||||
# Example:
|
||||
# .. cpp:function:: void f(int)
|
||||
# .. cpp:function:: void f(double)
|
||||
#
|
||||
# .. cpp:function:: void g()
|
||||
#
|
||||
# :cpp:any:`boom`
|
||||
#
|
||||
# So we disallow any signatures inside functions.
|
||||
parentSymbol = env.temp_data['cpp:parent_symbol']
|
||||
parentDecl = parentSymbol.declaration
|
||||
if parentDecl is not None and parentDecl.objectType == 'function':
|
||||
self.warn("C++ declarations inside functions are not supported." +
|
||||
" Parent function is " + text_type(parentSymbol.get_full_nested_name()))
|
||||
name = _make_phony_error_name()
|
||||
symbol = parentSymbol.add_name(name)
|
||||
env.temp_data['cpp:last_symbol'] = symbol
|
||||
return []
|
||||
return ObjectDescription.run(self)
|
||||
|
||||
def handle_signature(self, sig, signode):
|
||||
# type: (unicode, addnodes.desc_signature) -> Any
|
||||
if 'cpp:parent_symbol' not in self.env.temp_data:
|
||||
root = self.env.domaindata['cpp']['root_symbol']
|
||||
self.env.temp_data['cpp:parent_symbol'] = root
|
||||
self.env.ref_context['cpp:parent_key'] = root.get_lookup_key()
|
||||
parentSymbol = self.env.temp_data['cpp:parent_symbol']
|
||||
|
||||
parser = DefinitionParser(sig, self, self.env.config)
|
||||
|
||||
Reference in New Issue
Block a user