From a7be934ba2b0727b179b2328da82f8d863f0f6b4 Mon Sep 17 00:00:00 2001 From: Michael Woski Date: Wed, 27 Sep 2017 22:16:18 +0200 Subject: [PATCH] bug 525288 - resolve partial template specializations in CSourceHover/OpenDeclaration Change-Id: I61c06fc453499ddc2b1af73a8a69d4b648d473c3 Signed-off-by: Michael Woski --- .../cpp/semantics/HeuristicResolver.java | 2 +- .../selection/CPPSelectionTestsNoIndexer.java | 31 +++++++++++++++++-- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/HeuristicResolver.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/HeuristicResolver.java index b5d48fcfbb2..ba3dc410815 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/HeuristicResolver.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/HeuristicResolver.java @@ -512,7 +512,7 @@ public class HeuristicResolver { */ public static IBinding[] resolveUnknownBinding(ICPPUnknownBinding binding) { if (binding instanceof ICPPDeferredClassInstance) { - return new IBinding[] { ((ICPPDeferredClassInstance) binding).getClassTemplate() }; + return new IBinding[] { chooseTemplateForDeferredInstance((ICPPDeferredClassInstance) binding) }; } else if (binding instanceof ICPPUnknownMember) { Set lookupSet = new HashSet<>(); return lookInside(((ICPPUnknownMember) binding).getOwnerType(), false, diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/CPPSelectionTestsNoIndexer.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/CPPSelectionTestsNoIndexer.java index e26473f76d4..6425171d0cb 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/CPPSelectionTestsNoIndexer.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/CPPSelectionTestsNoIndexer.java @@ -45,6 +45,7 @@ import org.eclipse.cdt.core.testplugin.CProjectHelper; import org.eclipse.cdt.core.testplugin.FileManager; import org.eclipse.cdt.internal.core.dom.parser.ASTNode; +import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTNameBase; import org.eclipse.cdt.internal.ui.search.actions.OpenDeclarationsAction; @@ -1353,15 +1354,41 @@ public class CPPSelectionTestsNoIndexer extends BaseSelectionTests { public void testDependentAutoType_520913() throws Exception { String code = getAboveComment(); IFile file = importFile("testBug520913a.cpp", code); - + int offset = code.indexOf("auto test = ") + 2; IASTNode target = testF3(file, offset); assertInstance(target, IASTName.class); assertEquals("AA", ((IASTName) target).toString()); - + offset = code.indexOf("auto test()") + 2; target = testF3(file, offset); assertInstance(target, IASTName.class); assertEquals("AA", ((IASTName) target).toString()); } + + // template + // struct A {}; + // + // template<> + // struct A<0> {}; + // + // void test(){ + // A<0> a0; + // A<1> a1; + // } + public void testPartialSpecializationResolution_525288() throws Exception { + CPPASTNameBase.sAllowNameComputation = true; + String code = getAboveComment(); + IFile file = importFile("testBug525288.cpp", code); + + int offset = code.indexOf("a0") - 5; + IASTNode target = testF3(file, offset); + assertInstance(target, IASTName.class); + assertEquals("A<0>", ((IASTName) target).toString()); + + offset = code.indexOf("a1") - 5; + target = testF3(file, offset); + assertInstance(target, IASTName.class); + assertEquals("A", ((IASTName) target).toString()); + } }