1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-24 01:15:29 +02:00

Bug 412766. Check qualified names when doing base class lookup.

This commit is contained in:
Sergey Prigogin 2013-09-16 16:00:52 -07:00
parent bd922e4988
commit cb9d63e661
2 changed files with 34 additions and 11 deletions

View file

@ -1338,9 +1338,10 @@ public class IndexCPPBindingResolutionBugs extends IndexBindingResolutionTestBas
// class A { // class A {
// class B; // class B;
// }; // };
// class D : public A {}; // class D : public A {};
// class D::B {}; // class D::B {};
public void _testInvalidOwner_412766() throws Exception { public void testInvalidOwner_412766() throws Exception {
checkBindings(); getProblemFromFirstIdentifier("B {}");
} }
} }

View file

@ -11,6 +11,7 @@
package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet; import java.util.BitSet;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
@ -19,10 +20,14 @@ import java.util.List;
import org.eclipse.cdt.core.dom.IName; import org.eclipse.cdt.core.dom.IName;
import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNameOwner;
import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IProblemBinding; import org.eclipse.cdt.core.dom.ast.IProblemBinding;
import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNameSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBase; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBase;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
@ -160,8 +165,8 @@ class BaseClassLookup {
return info; return info;
} }
} }
// this is the first time to handle the class // This is the first time to handle the class.
BaseClassLookup result; BaseClassLookup result;
IBinding[] matches= IBinding.EMPTY_BINDING_ARRAY; IBinding[] matches= IBinding.EMPTY_BINDING_ARRAY;
if (baseClassScope == null) { if (baseClassScope == null) {
@ -171,13 +176,30 @@ class BaseClassLookup {
result= new BaseClassLookup(baseClassScope.getClassType(), data.getLookupPoint()); result= new BaseClassLookup(baseClassScope.getClassType(), data.getLookupPoint());
infoMap.put(baseClassScope, result); infoMap.put(baseClassScope, result);
try { try {
IBinding[] members= CPPSemantics.getBindingsFromScope(baseClassScope, data); // Determine the name qualifier if the lookup name is a definition.
if (members != null && members.length > 0 && members[0] != null) { ICPPASTNameSpecifier nameQualifier = null;
if (data.isPrefixLookup()) { if (data.qualified) {
matches= members; // Check if the name qualifier is in agreement with the base class name.
} else { IASTName lookupName = data.getLookupName();
result.setResult(members); if (lookupName != null && lookupName.getPropertyInParent() == ICPPASTQualifiedName.SEGMENT_NAME &&
return result; lookupName.getRoleOfName(false) == IASTNameOwner.r_definition) {
ICPPASTQualifiedName qName = (ICPPASTQualifiedName) lookupName.getParent();
ICPPASTNameSpecifier[] qualifiers = qName.getQualifier();
for (int i = 0; i < qualifiers.length && lookupName != qualifiers[i]; i++) {
nameQualifier = qualifiers[i];
}
}
}
if (nameQualifier == null || Arrays.equals(baseClassScope.getScopeName().getSimpleID(), nameQualifier.toCharArray())) {
IBinding[] members= CPPSemantics.getBindingsFromScope(baseClassScope, data);
if (members != null && members.length > 0 && members[0] != null) {
if (data.isPrefixLookup()) {
matches= members;
} else {
result.setResult(members);
return result;
}
} }
} }
} catch (DOMException e) { } catch (DOMException e) {