From 8a2d3674f62327f3250f12373b5500910e6d73d1 Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Tue, 24 May 2011 02:28:56 +0000 Subject: [PATCH] Bug 319632 - Name resolution gets thrown off by a namespace in an unrelated file. --- .../internal/index/tests/IndexBugsTests.java | 41 +++++++++++++++++-- .../parser/cpp/semantics/CPPSemantics.java | 18 +++++++- 2 files changed, 53 insertions(+), 6 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBugsTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBugsTests.java index 5db82078270..3ae8ffda9f6 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBugsTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBugsTests.java @@ -6,9 +6,9 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Markus Schorn - initial API and implementation - * Andrew Ferguson (Symbian) - * Sergey Prigogin (Google) + * Markus Schorn - initial API and implementation + * Andrew Ferguson (Symbian) + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.index.tests; @@ -404,7 +404,7 @@ public class IndexBugsTests extends BaseTestCase { String varName= "arrayDataSize"; StringBuffer content= new StringBuffer(); content.append("unsigned char arrayData[] = {\n"); - for (int i= 0; i< 1024 * 250 - 1; i++) { + for (int i= 0; i < 1024 * 250 - 1; i++) { content.append("0x00,"); } content.append("0x00};\n"); @@ -2016,6 +2016,39 @@ public class IndexBugsTests extends BaseTestCase { } } + // // header.h + // namespace ns2 { class A {}; } + + // #include "header.h" + // namespace ns1 { + // class B : public ns2::A {}; + // } + + // namespace ns1 { + // namespace ns2 { + // typedef int A; + // } + // } + public void testNamespaceReachability_319632() throws Exception { + waitForIndexer(); + + String[] testData = getContentsForTest(3); + TestSourceReader.createFile(fCProject.getProject(), "header.h", testData[0]); + IFile test= TestSourceReader.createFile(fCProject.getProject(), "test.cpp", testData[1]); + TestSourceReader.createFile(fCProject.getProject(), "unrelated.cpp", testData[2]); + final IIndexManager indexManager = CCorePlugin.getIndexManager(); + indexManager.reindex(fCProject); + waitForIndexer(); + IIndex index= indexManager.getIndex(fCProject); + index.acquireReadLock(); + try { + BindingAssertionHelper helper = new BindingAssertionHelper(test, testData[1], index); + helper.assertNonProblem("A", 1, ICPPClassType.class); + } finally { + index.releaseReadLock(); + } + } + // // a.h // #undef AAA 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 905c81e39eb..7cde6738e35 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 @@ -965,7 +965,7 @@ public class CPPSemantics { if (friendInLocalClass && !(scope instanceof ICPPClassScope)) return; - if (!data.contentAssist && data.hasResultOrProblem()) + if (!data.contentAssist && hasReachableResult(data)) return; // Lookup in base classes @@ -981,7 +981,7 @@ public class CPPSemantics { data.usingDirectivesOnly = true; } - // compute next scopes + // Compute next scopes if (useTemplScope && nextTmplScope != null) { nextTmplScope= enclosingTemplateScope(nextTmplScope.getTemplateDeclaration()); } else { @@ -990,6 +990,20 @@ public class CPPSemantics { } } + private static boolean hasReachableResult(LookupData data) { + if (data.foundItems instanceof Object[]) { + for (Object item : (Object[]) data.foundItems) { + if (item instanceof IBinding) { + IBinding binding = (IBinding) item; + if (!isFromIndex(binding) || data.tu == null || isReachableFromAst(data.tu, binding)) { + return true; + } + } + } + } + return false; + } + private static void lookupInlineNamespaces(LookupData data, IIndexFileSet fileSet, ICPPNamespaceScope namespace) throws DOMException { if (namespace instanceof ICPPInternalNamespaceScope) { ICPPInternalNamespaceScope ns= (ICPPInternalNamespaceScope) namespace;