From f7cf56f4c5a48a081ac777e9e1f114787ab07072 Mon Sep 17 00:00:00 2001 From: Nathan Ridge Date: Thu, 5 Feb 2015 02:38:53 -0500 Subject: [PATCH] Bug 458316 - Unqualified function call with dependent argument and non-matching overload in scope at point of declaration Change-Id: I2fc42e9ef9258c3c56791001217572fdd08f5025 Signed-off-by: Nathan Ridge --- .../parser/tests/ast2/AST2TemplateTests.java | 32 ++++++++++++++++++- .../parser/cpp/semantics/CPPSemantics.java | 30 ++++++++--------- 2 files changed, 46 insertions(+), 16 deletions(-) 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 33af5c62ce0..718be54a614 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 @@ -8184,7 +8184,7 @@ public class AST2TemplateTests extends AST2TestBase { public void testUnqualifiedFunctionCallInTemplate_402498a() throws Exception { parseAndCheckBindings(); } - + // template // auto foo(T t) -> decltype(bar(t)); // @@ -8222,6 +8222,36 @@ public class AST2TemplateTests extends AST2TestBase { assertFalse(x.getType().isSameType(CommonTypes.int_)); } + // void bar(); + // + // template + // void foo(T t) { + // bar(t); + // } + public void testUnqualifiedFunctionCallInTemplate_458316a() throws Exception { + parseAndCheckBindings(); + } + + // void bar(); + // + // template + // auto foo(T t) -> decltype(bar(t)); + // + // struct Cat { void meow(); }; + // + // namespace N { + // struct S {}; + // + // Cat bar(S); + // } + // + // int main() { + // foo(N::S()).meow(); + // } + public void testUnqualifiedFunctionCallInTemplate_458316b() throws Exception { + parseAndCheckBindings(); + } + // template // struct no_type {}; // 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 97790dceb64..40951dc337b 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 @@ -324,12 +324,21 @@ public class CPPSemantics { } private static IBinding postResolution(IBinding binding, LookupData data) { - if (binding instanceof IProblemBinding) - return binding; - - final IASTName lookupName = data.getLookupName(); - if (lookupName == null) - return binding; + final IASTName lookupName = data.getLookupName(); + if (lookupName == null) + return binding; + + // If this is the unqualified name of a function in a function call in a template and some + // of the function arguments are dependent, a matching function could be found via + // argument-dependent lookup at the point of instantiation. + if (binding == null || binding instanceof IProblemBinding) { + if (!data.qualified && data.isFunctionCall() && CPPTemplates.containsDependentType(data.getFunctionArgumentTypes())) { + binding = CPPDeferredFunction.createForName(lookupName.getSimpleID()); + } + } + + if (binding instanceof IProblemBinding) + return binding; IASTNode lookupPoint = data.getLookupPoint(); @@ -538,15 +547,6 @@ public class CPPSemantics { } } - // If this is the unqualified name of a function in a function call in a template and some - // of the function arguments are dependent, the name could be resolved via - // argument-dependent lookup at the point of instantiation. - if (binding == null) { - if (!data.qualified && data.isFunctionCall() && CPPTemplates.containsDependentType(data.getFunctionArgumentTypes())) { - binding = CPPDeferredFunction.createForName(lookupName.getSimpleID()); - } - } - // If we're still null... if (binding == null) { if (name instanceof ICPPASTQualifiedName && declaration != null) {