From c75374a1ef8ca975869d88ccddc1a22b2b10ffa4 Mon Sep 17 00:00:00 2001 From: Nathan Ridge Date: Wed, 13 May 2015 00:17:44 -0400 Subject: [PATCH] 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 --- .../parser/cpp/semantics/AccessContext.java | 25 +++++++++++-------- .../text/contentassist2/CompletionTests.java | 16 ++++++++++++ 2 files changed, 31 insertions(+), 10 deletions(-) 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); + } }