1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-05 08:46:02 +02:00

Bug 466861 - Do not lose template parameters of derived class when doing

access checking for content assist

Change-Id: I850bc2c1f7f49682fc51ad5be621a7125936dd08
Signed-off-by: Nathan Ridge <zeratul976@hotmail.com>
This commit is contained in:
Nathan Ridge 2015-05-13 00:17:44 -04:00
parent 165175210d
commit c75374a1ef
2 changed files with 31 additions and 10 deletions

View file

@ -173,22 +173,27 @@ public class AccessContext {
return true;
}
// Return true if 'c' is the same type as 'target', or a specialization of 'target'.
private static boolean isSameTypeOrSpecialization(ICPPClassType c, ICPPClassType target) {
if (!(c instanceof ICPPSpecialization)) {
while (target instanceof ICPPSpecialization) {
IBinding specialized = ((ICPPSpecialization) target).getSpecializedBinding();
if (specialized instanceof ICPPClassType) {
target = (ICPPClassType) specialized;
}
}
}
return c.isSameType(target);
}
private boolean isAccessible(IBinding binding, int bindingVisibility, ICPPClassType owner,
ICPPClassType derivedClass, int accessLevel, int depth) {
if (depth > CPPSemantics.MAX_INHERITANCE_DEPTH)
return false;
accessLevel = getMemberAccessLevel(derivedClass, accessLevel);
if (!(owner instanceof ICPPSpecialization)) {
while (derivedClass instanceof ICPPSpecialization) {
IBinding specialized = ((ICPPSpecialization) derivedClass).getSpecializedBinding();
if (specialized instanceof ICPPClassType) {
derivedClass = (ICPPClassType) specialized;
}
}
}
if (owner.isSameType(derivedClass)) {
if (isSameTypeOrSpecialization(owner, derivedClass)) {
return isAccessible(bindingVisibility, accessLevel);
}

View file

@ -1706,4 +1706,20 @@ public class CompletionTests extends AbstractContentAssistTest {
assertCompletionResults(fCursorOffset, expected, DISPLAY);
assertDotReplacedWithArrow();
}
// struct A {
// void foo();
// };
//
// template <class T>
// class C : public T {};
//
// int main() {
// C<A> c;
// c./*cursor*/
// }
public void testInheritanceFromTemplateParameter_bug466861() throws Exception {
final String[] expected = { "A", "C", "foo(void)" };
assertCompletionResults(fCursorOffset, expected, ID);
}
}