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 00e661556e4..a8a937771f0 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 @@ -8164,4 +8164,20 @@ public class AST2TemplateTests extends AST2TestBase { public void testSpecializedEnumerator_418770() throws Exception { parseAndCheckBindings(); } + + // template + // class A; + // + // namespace ns { + // template + // int waldo(const A&); + // } + // + // template + // class A { + // friend int ns::waldo(const A&); + // }; + public void testDependentSpecializationOfFunctionTemplateAsFriend_422505() throws Exception { + parseAndCheckBindings(); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java index f2343632b29..ecd3b3dbc9d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java @@ -2648,6 +2648,12 @@ public class CPPSemantics { for (ICPPFunction fn : fns) { if (fn instanceof ICPPFunctionTemplate && !(fn instanceof IProblemBinding) && !(fn instanceof ICPPUnknownBinding)) { + // If the declared function type is dependent, there is no point trying to use it + // to instantiate the template, so return a deferred function instead. + // Note that CPPTemplates.instantiateForFunctionCall() behaves similarly. + if (CPPTemplates.isDependentType(ft)) { + return CPPDeferredFunction.createForCandidates(fns); + } ICPPFunctionTemplate template= (ICPPFunctionTemplate) fn; ICPPFunction inst= CPPTemplates.instantiateForFunctionDeclaration(template, tmplArgs, ft, data.getLookupPoint()); if (inst != null) {