diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java index 44d7e876530..443e4bae6b1 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java @@ -9326,4 +9326,12 @@ public class AST2CPPTests extends AST2BaseTest { public void testMemberInitializer_333200() throws Exception { parseAndCheckBindings(); } + + // template auto add(T t, U u) -> decltype(t + u); + // template auto add(T t, U u) -> decltype(t + u) { + // return t + u; + // } + public void testResolutionInTrailingReturnType_333256() throws Exception { + parseAndCheckBindings(); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java index 6bb3f274196..9ad88841064 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java @@ -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 null if the given node