mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-23 17:05:26 +02:00
Bug 412766. Check qualified names when doing base class lookup.
This commit is contained in:
parent
bd922e4988
commit
cb9d63e661
2 changed files with 34 additions and 11 deletions
|
@ -1338,9 +1338,10 @@ public class IndexCPPBindingResolutionBugs extends IndexBindingResolutionTestBas
|
|||
// class A {
|
||||
// class B;
|
||||
// };
|
||||
|
||||
// class D : public A {};
|
||||
// class D::B {};
|
||||
public void _testInvalidOwner_412766() throws Exception {
|
||||
checkBindings();
|
||||
public void testInvalidOwner_412766() throws Exception {
|
||||
getProblemFromFirstIdentifier("B {}");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.BitSet;
|
||||
import java.util.Collections;
|
||||
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.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.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IProblemBinding;
|
||||
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.ICPPClassScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
||||
|
@ -160,8 +165,8 @@ class BaseClassLookup {
|
|||
return info;
|
||||
}
|
||||
}
|
||||
|
||||
// this is the first time to handle the class
|
||||
|
||||
// This is the first time to handle the class.
|
||||
BaseClassLookup result;
|
||||
IBinding[] matches= IBinding.EMPTY_BINDING_ARRAY;
|
||||
if (baseClassScope == null) {
|
||||
|
@ -171,13 +176,30 @@ class BaseClassLookup {
|
|||
result= new BaseClassLookup(baseClassScope.getClassType(), data.getLookupPoint());
|
||||
infoMap.put(baseClassScope, result);
|
||||
try {
|
||||
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;
|
||||
// Determine the name qualifier if the lookup name is a definition.
|
||||
ICPPASTNameSpecifier nameQualifier = null;
|
||||
if (data.qualified) {
|
||||
// Check if the name qualifier is in agreement with the base class name.
|
||||
IASTName lookupName = data.getLookupName();
|
||||
if (lookupName != null && lookupName.getPropertyInParent() == ICPPASTQualifiedName.SEGMENT_NAME &&
|
||||
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) {
|
||||
|
|
Loading…
Add table
Reference in a new issue