1
0
Fork 0
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:
Markus Schorn 2011-01-07 12:37:02 +00:00
parent c3d083bf06
commit e3fcf44ebd
2 changed files with 39 additions and 21 deletions

View file

@ -9326,4 +9326,12 @@ public class AST2CPPTests extends AST2BaseTest {
public void testMemberInitializer_333200() throws Exception { public void testMemberInitializer_333200() throws Exception {
parseAndCheckBindings(); 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();
}
} }

View file

@ -876,31 +876,18 @@ public class CPPVisitor extends ASTQueries {
node= node.getParent(); node= node.getParent();
} }
continue; continue;
} else if (prop == ICPPASTFunctionDeclarator.TRAILING_RETURN_TYPE) {
IScope result = scopeViaFunctionDtor((ICPPASTFunctionDeclarator) node.getParent());
if (result != null)
return result;
} }
} else if (node instanceof IASTParameterDeclaration) { } else if (node instanceof IASTParameterDeclaration) {
IASTNode parent = node.getParent(); IASTNode parent = node.getParent();
if (parent instanceof ICPPASTFunctionDeclarator) { if (parent instanceof ICPPASTFunctionDeclarator) {
ICPPASTFunctionDeclarator dtor = (ICPPASTFunctionDeclarator) parent; IScope result = scopeViaFunctionDtor((ICPPASTFunctionDeclarator) parent);
if (ASTQueries.findTypeRelevantDeclarator(dtor) == dtor) { if (result != null)
while (parent.getParent() instanceof IASTDeclarator) return result;
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();
}
}
} else if (parent instanceof ICPPASTTemplateDeclaration) { } else if (parent instanceof ICPPASTTemplateDeclaration) {
return CPPTemplates.getContainingScope(node); return CPPTemplates.getContainingScope(node);
} }
@ -1001,6 +988,29 @@ public class CPPVisitor extends ASTQueries {
return new CPPScope.CPPScopeProblem(inputNode, IProblemBinding.SEMANTIC_BAD_SCOPE, return new CPPScope.CPPScopeProblem(inputNode, IProblemBinding.SEMANTIC_BAD_SCOPE,
inputNode.getRawSignature().toCharArray()); 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 * Returns enclosing function definition, or <code>null</code> if the given node