From bb9d1db32349d7c217fb2b964e45ee15f4e100cb Mon Sep 17 00:00:00 2001 From: Nathan Ridge Date: Wed, 20 Sep 2017 18:25:48 -0400 Subject: [PATCH] Bug 518937 - Apply declaredBefore() filtering to index bindings found in a namespace scope Previously, such filtering was only done in resolveAmbiguities(), which was too late for name lookup for proceed to an enclosing scope if it did not find valid candidates in the namespace scope. Change-Id: I435d7be1aff5344985c1bbb201bf5d383d43fe8d --- .../index/tests/IndexMultiFileTest.java | 27 +++++++++++++------ .../core/dom/parser/cpp/CPPScope.java | 7 ++++- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexMultiFileTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexMultiFileTest.java index 10ce5ef99b2..edd950758da 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexMultiFileTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexMultiFileTest.java @@ -10,14 +10,6 @@ *******************************************************************************/ package org.eclipse.cdt.internal.index.tests; -import org.eclipse.cdt.core.CCorePlugin; -import org.eclipse.cdt.core.dom.IPDOMManager; -import org.eclipse.cdt.core.model.ICProject; -import org.eclipse.cdt.core.testplugin.CProjectHelper; -import org.eclipse.cdt.core.testplugin.util.TestSourceReader; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IProjectDescription; - import junit.framework.TestSuite; /** @@ -351,4 +343,23 @@ public class IndexMultiFileTest extends IndexBindingResolutionTestBase { public void testStackOverflow_514459() throws Exception { checkBindings(); } + + + //test.hpp * + // template class A {}; + // + // struct C { + // C(); + // }; + // + // namespace Ptr2 { + // using C = A; + // } + + //test.cpp + // #include "test.hpp" + // C::C() {} + public void testAliasTemplateReferencingSameName_518937() throws Exception { + checkBindings(); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPScope.java index badcb044d2b..101e80511a7 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPScope.java @@ -213,7 +213,12 @@ abstract public class CPPScope implements ICPPASTInternalScope { if (binding instanceof ICPPNamespace) { ICPPNamespaceScope indexNs = ((ICPPNamespace) binding).getNamespaceScope(); IBinding[] bindings = indexNs.getBindings(lookup); - result = ArrayUtil.addAll(IBinding.class, result, bindings); + for (IBinding candidate : bindings) { + if (lookup.isPrefixLookup() || + CPPSemantics.declaredBefore(candidate, lookup.getLookupPoint(), true)) { + result = ArrayUtil.append(result, candidate); + } + } } } catch (CoreException e) { CCorePlugin.log(e);