From d6a510ab069d427a9f4a0d9c705832a0ce763764 Mon Sep 17 00:00:00 2001 From: Michi Date: Tue, 6 Jan 2015 08:45:59 +0100 Subject: [PATCH] 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 Reviewed-on: https://git.eclipse.org/r/39016 Reviewed-by: Sergey Prigogin Tested-by: Sergey Prigogin --- .../parser/cpp/semantics/AccessContext.java | 16 +++++++++++++-- .../text/contentassist2/CompletionTests.java | 20 ++++++++++++++++++- 2 files changed, 33 insertions(+), 3 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 4b111b51fa8..ae20e9dc72e 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 @@ -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(); 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 d6663d6a837..4c94e10651b 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 @@ -743,7 +743,7 @@ public class CompletionTests extends AbstractContentAssistTest { // using TParam = T; // }; // }; - // + // // struct NestingTest: Parent { // struct A : Nested { // TP/*cursor*/ @@ -754,6 +754,24 @@ public class CompletionTests extends AbstractContentAssistTest { assertCompletionResults(fCursorOffset, expected, ID); } + // template + // class Parent { + // struct NestedHidden {}; + // protected: + // struct NestedProtected {}; + // public: + // struct NestedPublic {}; + // }; + // + // template + // class NestingTest: Parent { + // Parent::/*cursor*/ + // }; + public void testNestedBaseTemplateMembersFromUnknownScope_456752() throws Exception { + final String[] expected = { "NestedProtected", "NestedPublic" }; + assertCompletionResults(fCursorOffset, expected, ID); + } + // struct A {}; // // template