mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Bug 333256: Name resolution in trailing return type.
This commit is contained in:
parent
c3d083bf06
commit
e3fcf44ebd
2 changed files with 39 additions and 21 deletions
|
@ -9326,4 +9326,12 @@ public class AST2CPPTests extends AST2BaseTest {
|
|||
public void testMemberInitializer_333200() throws Exception {
|
||||
parseAndCheckBindings();
|
||||
}
|
||||
|
||||
// template <typename T, typename U> auto add(T t, U u) -> decltype(t + u);
|
||||
// template <typename T, typename U> auto add(T t, U u) -> decltype(t + u) {
|
||||
// return t + u;
|
||||
// }
|
||||
public void testResolutionInTrailingReturnType_333256() throws Exception {
|
||||
parseAndCheckBindings();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -876,31 +876,18 @@ public class CPPVisitor extends ASTQueries {
|
|||
node= node.getParent();
|
||||
}
|
||||
continue;
|
||||
} else if (prop == ICPPASTFunctionDeclarator.TRAILING_RETURN_TYPE) {
|
||||
IScope result = scopeViaFunctionDtor((ICPPASTFunctionDeclarator) node.getParent());
|
||||
if (result != null)
|
||||
return result;
|
||||
|
||||
}
|
||||
} else if (node instanceof IASTParameterDeclaration) {
|
||||
IASTNode parent = node.getParent();
|
||||
if (parent instanceof ICPPASTFunctionDeclarator) {
|
||||
ICPPASTFunctionDeclarator dtor = (ICPPASTFunctionDeclarator) parent;
|
||||
if (ASTQueries.findTypeRelevantDeclarator(dtor) == dtor) {
|
||||
while (parent.getParent() instanceof IASTDeclarator)
|
||||
parent = parent.getParent();
|
||||
ASTNodeProperty prop = parent.getPropertyInParent();
|
||||
if (prop == IASTSimpleDeclaration.DECLARATOR) {
|
||||
return dtor.getFunctionScope();
|
||||
}
|
||||
if (prop == IASTFunctionDefinition.DECLARATOR) {
|
||||
final IASTCompoundStatement body = (IASTCompoundStatement) ((IASTFunctionDefinition) parent.getParent()).getBody();
|
||||
if (body != null)
|
||||
return body.getScope();
|
||||
return dtor.getFunctionScope();
|
||||
}
|
||||
if (prop == ICPPASTLambdaExpression.DECLARATOR) {
|
||||
final IASTCompoundStatement body = ((ICPPASTLambdaExpression) parent.getParent()).getBody();
|
||||
if (body != null)
|
||||
return body.getScope();
|
||||
return dtor.getFunctionScope();
|
||||
}
|
||||
}
|
||||
IScope result = scopeViaFunctionDtor((ICPPASTFunctionDeclarator) parent);
|
||||
if (result != null)
|
||||
return result;
|
||||
} else if (parent instanceof ICPPASTTemplateDeclaration) {
|
||||
return CPPTemplates.getContainingScope(node);
|
||||
}
|
||||
|
@ -1001,6 +988,29 @@ public class CPPVisitor extends ASTQueries {
|
|||
return new CPPScope.CPPScopeProblem(inputNode, IProblemBinding.SEMANTIC_BAD_SCOPE,
|
||||
inputNode.getRawSignature().toCharArray());
|
||||
}
|
||||
|
||||
private static IScope scopeViaFunctionDtor(ICPPASTFunctionDeclarator dtor) {
|
||||
if (ASTQueries.findTypeRelevantDeclarator(dtor) == dtor) {
|
||||
IASTDeclarator outerDtor = ASTQueries.findOutermostDeclarator(dtor);
|
||||
ASTNodeProperty prop = outerDtor.getPropertyInParent();
|
||||
if (prop == IASTSimpleDeclaration.DECLARATOR) {
|
||||
return dtor.getFunctionScope();
|
||||
}
|
||||
if (prop == IASTFunctionDefinition.DECLARATOR) {
|
||||
final IASTCompoundStatement body = (IASTCompoundStatement) ((IASTFunctionDefinition) outerDtor.getParent()).getBody();
|
||||
if (body != null)
|
||||
return body.getScope();
|
||||
return dtor.getFunctionScope();
|
||||
}
|
||||
if (prop == ICPPASTLambdaExpression.DECLARATOR) {
|
||||
final IASTCompoundStatement body = ((ICPPASTLambdaExpression) outerDtor.getParent()).getBody();
|
||||
if (body != null)
|
||||
return body.getScope();
|
||||
return dtor.getFunctionScope();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns enclosing function definition, or <code>null</code> if the given node
|
||||
|
|
Loading…
Add table
Reference in a new issue