mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Bug 456752 - [Code Assist] - Accessibility check is broken for base
class templates of a class template There are 2 changes. Finding the proper naming scope, which basically is the same as what is done in CPPUnknownTypeScope.getBindings when retrieving the bindings themselves. The second change was picking the right scope for the actual accessibility check for base templates. Change-Id: I535c8cdd9d07272d37da9d23a03edb9e6b1b3a7a Signed-off-by: Michi <woskimi@yahoo.de> Reviewed-on: https://git.eclipse.org/r/39016 Reviewed-by: Sergey Prigogin <eclipse.sprigogin@gmail.com> Tested-by: Sergey Prigogin <eclipse.sprigogin@gmail.com>
This commit is contained in:
parent
0f94c4a067
commit
d6a510ab06
2 changed files with 33 additions and 3 deletions
|
@ -18,6 +18,7 @@ import org.eclipse.cdt.core.dom.ast.IASTNode;
|
|||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.ICompositeType;
|
||||
import org.eclipse.cdt.core.dom.ast.IProblemBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPAliasTemplateInstance;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBase;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope;
|
||||
|
@ -33,6 +34,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
|
|||
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPDeferredClassInstance;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalUnknownScope;
|
||||
|
||||
/**
|
||||
* The context that determines access to private and protected class members.
|
||||
|
@ -236,6 +238,9 @@ public class AccessContext {
|
|||
if (bases != null) {
|
||||
for (ICPPBase base : bases) {
|
||||
IBinding baseClass = base.getBaseClass();
|
||||
if (baseClass instanceof ICPPDeferredClassInstance) {
|
||||
baseClass = ((ICPPDeferredClassInstance) baseClass).getTemplateDefinition();
|
||||
}
|
||||
if (!(baseClass instanceof ICPPClassType)) {
|
||||
continue;
|
||||
}
|
||||
|
@ -254,9 +259,16 @@ public class AccessContext {
|
|||
LookupData data = new LookupData(name);
|
||||
isUnqualifiedLookup= !data.qualified;
|
||||
|
||||
ICPPScope scope= CPPSemantics.getLookupScope(name);
|
||||
ICPPScope scope = CPPSemantics.getLookupScope(name);
|
||||
while (scope != null && !(scope instanceof ICPPClassScope)) {
|
||||
scope = CPPSemantics.getParentScope(scope, data.getTranslationUnit());
|
||||
if (scope instanceof ICPPInternalUnknownScope) {
|
||||
IType scopeType = ((ICPPInternalUnknownScope) scope).getScopeType();
|
||||
if (scopeType instanceof ICPPDeferredClassInstance) {
|
||||
return ((ICPPDeferredClassInstance) scopeType).getClassTemplate();
|
||||
}
|
||||
} else {
|
||||
scope = CPPSemantics.getParentScope(scope, data.getTranslationUnit());
|
||||
}
|
||||
}
|
||||
if (scope instanceof ICPPClassScope) {
|
||||
return ((ICPPClassScope) scope).getClassType();
|
||||
|
|
|
@ -743,7 +743,7 @@ public class CompletionTests extends AbstractContentAssistTest {
|
|||
// using TParam = T;
|
||||
// };
|
||||
// };
|
||||
//
|
||||
//
|
||||
// struct NestingTest: Parent<int> {
|
||||
// struct A : Nested {
|
||||
// TP/*cursor*/
|
||||
|
@ -754,6 +754,24 @@ public class CompletionTests extends AbstractContentAssistTest {
|
|||
assertCompletionResults(fCursorOffset, expected, ID);
|
||||
}
|
||||
|
||||
// template<typename T>
|
||||
// class Parent {
|
||||
// struct NestedHidden {};
|
||||
// protected:
|
||||
// struct NestedProtected {};
|
||||
// public:
|
||||
// struct NestedPublic {};
|
||||
// };
|
||||
//
|
||||
// template<typename T>
|
||||
// class NestingTest: Parent<T> {
|
||||
// Parent<T>::/*cursor*/
|
||||
// };
|
||||
public void testNestedBaseTemplateMembersFromUnknownScope_456752() throws Exception {
|
||||
final String[] expected = { "NestedProtected", "NestedPublic" };
|
||||
assertCompletionResults(fCursorOffset, expected, ID);
|
||||
}
|
||||
|
||||
// struct A {};
|
||||
//
|
||||
// template<typename T>
|
||||
|
|
Loading…
Add table
Reference in a new issue