From 8b68a2bb8e675fac18c29c3f8f284ef8523a509a Mon Sep 17 00:00:00 2001 From: Nathan Ridge Date: Sat, 9 Jan 2016 01:03:27 -0500 Subject: [PATCH] Bug 485383 - Exclude constructors when expanding using-declarations during name lookup This helps us respect the standard's rule that name lookup does not find constructors, and avoid ambiguities between class and constructor names that result otherwise. Change-Id: I17b907bcb35108d7d7e0cc72ca70e07481a5b9ed Signed-off-by: Nathan Ridge --- .../cdt/core/parser/tests/ast2/AST2CPPTests.java | 10 ++++++++++ .../core/dom/parser/cpp/semantics/CPPSemantics.java | 12 +++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) 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 e637924a1eb..9e9842ec3b3 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 @@ -1477,6 +1477,16 @@ public class AST2CPPTests extends AST2TestBase { public void _testInheritedTemplateConstructor() throws Exception { parseAndCheckBindings(); } + + // struct base {}; + // + // struct derived : public base { + // using base::base; + // base waldo() const; + // }; + public void testInheritedConstructorShadowingBaseClassName_485383() throws Exception { + parseAndCheckBindings(); + } // class A { ~A(); }; // class B { ~B(void); }; 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 0bfa474a5ef..f3200ab85de 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 @@ -1360,7 +1360,17 @@ public class CPPSemantics { if (b instanceof ICPPUsingDeclaration) { if (data.forDeclaration() == null) { for (IBinding d : ((ICPPUsingDeclaration) b).getDelegates()) { - if (d != null && !(data.typesOnly && isObject(d))) { + // Note on excluding constructors: + // Constructors are never found during name lookup ([class.ctor] p2). + // Binding resolution sometimes resolves names to constructors, and as + // such, the delegates of a using-declaration can include constructors, + // but when using these delegates in the process of name lookup, + // constructors are ignored. If the binding resolution triggering this + // name lookup wants to ultimately resolve to a constructor, it can do so + // after the name lookup phase, e.g. in the convertClassToConstructor() + // call in postResolution(). + if (d != null && !(data.typesOnly && isObject(d)) && + !(d instanceof ICPPConstructor)) { result.add(d); } }