mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-03 14:25:37 +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
|
@ -404,7 +404,7 @@ public class IndexBugsTests extends BaseTestCase {
|
||||||
String varName= "arrayDataSize";
|
String varName= "arrayDataSize";
|
||||||
StringBuffer content= new StringBuffer();
|
StringBuffer content= new StringBuffer();
|
||||||
content.append("unsigned char arrayData[] = {\n");
|
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,");
|
||||||
}
|
}
|
||||||
content.append("0x00};\n");
|
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
|
// // a.h
|
||||||
// #undef AAA
|
// #undef AAA
|
||||||
|
|
||||||
|
|
|
@ -965,7 +965,7 @@ public class CPPSemantics {
|
||||||
|
|
||||||
if (friendInLocalClass && !(scope instanceof ICPPClassScope))
|
if (friendInLocalClass && !(scope instanceof ICPPClassScope))
|
||||||
return;
|
return;
|
||||||
if (!data.contentAssist && data.hasResultOrProblem())
|
if (!data.contentAssist && hasReachableResult(data))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Lookup in base classes
|
// Lookup in base classes
|
||||||
|
@ -981,7 +981,7 @@ public class CPPSemantics {
|
||||||
data.usingDirectivesOnly = true;
|
data.usingDirectivesOnly = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// compute next scopes
|
// Compute next scopes
|
||||||
if (useTemplScope && nextTmplScope != null) {
|
if (useTemplScope && nextTmplScope != null) {
|
||||||
nextTmplScope= enclosingTemplateScope(nextTmplScope.getTemplateDeclaration());
|
nextTmplScope= enclosingTemplateScope(nextTmplScope.getTemplateDeclaration());
|
||||||
} else {
|
} 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 {
|
private static void lookupInlineNamespaces(LookupData data, IIndexFileSet fileSet, ICPPNamespaceScope namespace) throws DOMException {
|
||||||
if (namespace instanceof ICPPInternalNamespaceScope) {
|
if (namespace instanceof ICPPInternalNamespaceScope) {
|
||||||
ICPPInternalNamespaceScope ns= (ICPPInternalNamespaceScope) namespace;
|
ICPPInternalNamespaceScope ns= (ICPPInternalNamespaceScope) namespace;
|
||||||
|
|
Loading…
Add table
Reference in a new issue