diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/AccessContext.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/AccessContext.java index c42cef4314e..6d4a4621438 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/AccessContext.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/AccessContext.java @@ -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); } diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CompletionTests.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CompletionTests.java index 0b4a9689770..256bf4063b4 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CompletionTests.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CompletionTests.java @@ -1706,4 +1706,20 @@ public class CompletionTests extends AbstractContentAssistTest { assertCompletionResults(fCursorOffset, expected, DISPLAY); assertDotReplacedWithArrow(); } + + // struct A { + // void foo(); + // }; + // + // template + // class C : public T {}; + // + // int main() { + // C c; + // c./*cursor*/ + // } + public void testInheritanceFromTemplateParameter_bug466861() throws Exception { + final String[] expected = { "A", "C", "foo(void)" }; + assertCompletionResults(fCursorOffset, expected, ID); + } }