diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java index 58a8e5af278..ee85cd65de3 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java @@ -3844,4 +3844,18 @@ public class AST2TemplateTests extends AST2BaseTest { String code= getAboveComment(); parseAndCheckBindings(code, ParserLanguage.CPP); } + + // template class CT {}; + // template CT& getline1(CT& __in); + // template CT& getline2(CT& __in); + // void test() { + // CT i; + // getline2(i); + // } + public void testAmbiguousDeclaratorInFunctionTemplate_265342() throws Exception { + final String code = getAboveComment(); + BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + bh.assertNonProblem("getline2(i)", 8, ICPPTemplateInstance.class); + parseAndCheckBindings(code, ParserLanguage.CPP); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguityResolver.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguityResolver.java index 641c8fe53b8..36fbb94b256 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguityResolver.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguityResolver.java @@ -166,7 +166,7 @@ final class CPPASTAmbiguityResolver extends ASTVisitor { } private void repopulateScope(IASTDeclaration declaration) { - IScope scope= CPPVisitor.getContainingScope(declaration); + IScope scope= CPPVisitor.getContainingNonTemplateScope(declaration); if (scope instanceof ICPPASTInternalScope) { CPPSemantics.populateCache((ICPPASTInternalScope) scope, declaration); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousCondition.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousCondition.java index 49fd7bf2e5b..9257b512f16 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousCondition.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousCondition.java @@ -44,7 +44,7 @@ public class CPPASTAmbiguousCondition extends ASTAmbiguousNode implements IASTAm @Override protected void beforeResolution() { // populate containing scope, so that it will not be affected by the alternative branches. - IScope scope= CPPVisitor.getContainingScope(this); + IScope scope= CPPVisitor.getContainingNonTemplateScope(this); if (scope instanceof ICPPASTInternalScope) { ((ICPPASTInternalScope) scope).populateCache(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousDeclarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousDeclarator.java index 1b516bda6ce..458d3d13d16 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousDeclarator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousDeclarator.java @@ -44,7 +44,7 @@ public class CPPASTAmbiguousDeclarator extends ASTAmbiguousNode implements IASTA @Override protected void beforeResolution() { // populate containing scope, so that it will not be affected by the alternative branches. - IScope scope= CPPVisitor.getContainingScope(this); + IScope scope= CPPVisitor.getContainingNonTemplateScope(this); if (scope instanceof ICPPASTInternalScope) { ((ICPPASTInternalScope) scope).populateCache(); } 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 581e8d32863..ed06f530b7b 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 @@ -578,11 +578,8 @@ public class CPPVisitor extends ASTQueries { IBinding binding= null; final boolean template= tmplDecl != null; boolean isFriendDecl= false; - ICPPScope scope = (ICPPScope) getContainingScope((IASTNode) name); + ICPPScope scope = (ICPPScope) getContainingNonTemplateScope(name); try { - while (scope instanceof ICPPTemplateScope) { - scope= (ICPPScope) scope.getParent(); - } if (parent instanceof IASTSimpleDeclaration && scope instanceof ICPPClassScope) { ICPPASTDeclSpecifier declSpec = (ICPPASTDeclSpecifier) ((IASTSimpleDeclaration) parent).getDeclSpecifier(); if (declSpec.isFriend()) {