mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-31 04:45:38 +02:00
Bug 319632 - Name resolution gets thrown off by a namespace in an unrelated file.
This commit is contained in:
parent
f118967040
commit
8a2d3674f6
2 changed files with 53 additions and 6 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Reference in a new issue