1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-09 18:15:23 +02:00

Bug 481161 - Namespace resolution problem with index

Change-Id: I2adaa53647bcd67f0a1058de4d44dbc808ff84a9
This commit is contained in:
Sergey Prigogin 2015-10-30 16:02:44 -07:00
parent ef148a9ec5
commit dc9dfa517b
2 changed files with 38 additions and 5 deletions

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2013, 2014 Google, Inc and others. * Copyright (c) 2013, 2015 Google, Inc and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -100,4 +100,28 @@ public class IndexMultiFileTest extends IndexBindingResolutionTestBase {
public void testNamespaceAlias_442117() throws Exception { public void testNamespaceAlias_442117() throws Exception {
checkBindings(); checkBindings();
} }
// confuser.cpp
// namespace ns1 {
// namespace waldo {}
// namespace ns2 {
// namespace waldo {}
// }
// }
// test.cpp *
// namespace waldo {
// class A {};
// }
//
// namespace ns1 {
// namespace ns2 {
//
// waldo::A* x;
//
// }
// }
public void testNamespace_481161() throws Exception {
checkBindings();
}
} }

View file

@ -2013,6 +2013,7 @@ public class CPPSemantics {
ObjectSet<ICPPFunction> fns= ObjectSet.emptySet(); ObjectSet<ICPPFunction> fns= ObjectSet.emptySet();
IBinding type = null; IBinding type = null;
IBinding obj = null; IBinding obj = null;
boolean ambiguous = false;
IBinding temp = null; IBinding temp = null;
final CPPASTTranslationUnit tu = data.getTranslationUnit(); final CPPASTTranslationUnit tu = data.getTranslationUnit();
@ -2083,25 +2084,28 @@ public class CPPSemantics {
if (type == null) { if (type == null) {
type = temp; type = temp;
ambiguous = false;
} else if (!type.equals(temp)) { } else if (!type.equals(temp)) {
int c = compareByRelevance(tu, type, temp); int c = compareByRelevance(tu, type, temp);
if (c < 0) { if (c < 0) {
type= temp; type= temp;
ambiguous = false;
} else if (c == 0) { } else if (c == 0) {
if (((IType) type).isSameType((IType) temp)) { if (((IType) type).isSameType((IType) temp)) {
if (type instanceof ITypedef && !(temp instanceof ITypedef)) { if (type instanceof ITypedef && !(temp instanceof ITypedef)) {
// Between same types prefer non-typedef. // Between same types prefer non-typedef.
type= temp; type= temp;
ambiguous = false;
} }
} else { } else {
return new ProblemBinding(lookupName, lookupPoint, ambiguous = true;
IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, data.getFoundBindings());
} }
} }
} }
} else { } else {
if (obj == null) { if (obj == null) {
obj = temp; obj = temp;
ambiguous = false;
} else if (!obj.equals(temp)) { } else if (!obj.equals(temp)) {
if (obj instanceof ICPPNamespace && temp instanceof ICPPNamespace && if (obj instanceof ICPPNamespace && temp instanceof ICPPNamespace &&
SemanticUtil.isSameNamespace((ICPPNamespace) obj, (ICPPNamespace) temp)) { SemanticUtil.isSameNamespace((ICPPNamespace) obj, (ICPPNamespace) temp)) {
@ -2110,13 +2114,18 @@ public class CPPSemantics {
int c = compareByRelevance(tu, obj, temp); int c = compareByRelevance(tu, obj, temp);
if (c < 0) { if (c < 0) {
obj= temp; obj= temp;
ambiguous = false;
} else if (c == 0) { } else if (c == 0) {
return new ProblemBinding(lookupName, lookupPoint, ambiguous = true;
IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, data.getFoundBindings());
} }
} }
} }
} }
if (ambiguous) {
return new ProblemBinding(lookupName, lookupPoint,
IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, data.getFoundBindings());
}
if (data.forUsingDeclaration) { if (data.forUsingDeclaration) {
int cmp= -1; int cmp= -1;
if (obj != null) { if (obj != null) {