From 4ae2381430013b64a3c013c62bf038f3fa659f66 Mon Sep 17 00:00:00 2001 From: Ilya Biryukov Date: Fri, 27 Sep 2019 17:55:46 +0000 Subject: [PATCH] [clangd] Fix template type aliases in findExplicitReference Reviewers: kadircet Reviewed By: kadircet Subscribers: MaskRay, jkorous, arphaman, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D68124 llvm-svn: 373104 --- clang-tools-extra/clangd/FindTarget.cpp | 25 +++++++++++++++------- .../clangd/unittests/FindTargetTests.cpp | 24 ++++++++++----------- 2 files changed, 28 insertions(+), 21 deletions(-) diff --git a/clang-tools-extra/clangd/FindTarget.cpp b/clang-tools-extra/clangd/FindTarget.cpp index 6bbaa5e..08bdf97 100644 --- a/clang-tools-extra/clangd/FindTarget.cpp +++ b/clang-tools-extra/clangd/FindTarget.cpp @@ -477,13 +477,6 @@ Optional refInTypeLoc(TypeLoc L) { Ref->Qualifier = L.getQualifierLoc(); } - void VisitDeducedTemplateSpecializationTypeLoc( - DeducedTemplateSpecializationTypeLoc L) { - Ref = ReferenceLoc{ - NestedNameSpecifierLoc(), L.getNameLoc(), - explicitReferenceTargets(DynTypedNode::create(L.getType()))}; - } - void VisitTagTypeLoc(TagTypeLoc L) { Ref = ReferenceLoc{NestedNameSpecifierLoc(), L.getNameLoc(), {L.getDecl()}}; @@ -495,9 +488,25 @@ Optional refInTypeLoc(TypeLoc L) { } void VisitTemplateSpecializationTypeLoc(TemplateSpecializationTypeLoc L) { + // We must ensure template type aliases are included in results if they + // were written in the source code, e.g. in + // template using valias = vector; + // ^valias x; + // 'explicitReferenceTargets' will return: + // 1. valias with mask 'Alias'. + // 2. 'vector' with mask 'Underlying'. + // we want to return only #1 in this case. Ref = ReferenceLoc{ NestedNameSpecifierLoc(), L.getTemplateNameLoc(), - explicitReferenceTargets(DynTypedNode::create(L.getType()))}; + explicitReferenceTargets(DynTypedNode::create(L.getType()), + DeclRelation::Alias)}; + } + void VisitDeducedTemplateSpecializationTypeLoc( + DeducedTemplateSpecializationTypeLoc L) { + Ref = ReferenceLoc{ + NestedNameSpecifierLoc(), L.getNameLoc(), + explicitReferenceTargets(DynTypedNode::create(L.getType()), + DeclRelation::Alias)}; } void VisitDependentTemplateSpecializationTypeLoc( diff --git a/clang-tools-extra/clangd/unittests/FindTargetTests.cpp b/clang-tools-extra/clangd/unittests/FindTargetTests.cpp index 32aa25a..91f78e3 100644 --- a/clang-tools-extra/clangd/unittests/FindTargetTests.cpp +++ b/clang-tools-extra/clangd/unittests/FindTargetTests.cpp @@ -615,20 +615,18 @@ TEST_F(FindExplicitReferencesTest, All) { )cpp", "0: targets = {vector}\n" "1: targets = {vector}\n"}, - // FIXME: Fix 'allTargetDecls' to return alias template and re-enable. // Template type aliases. - // {R"cpp( - // template struct vector { using value_type = T; }; - // template <> struct vector { using value_type = bool; }; - // template using valias = vector; - // void foo() { - // $0^valias vi; - // $1^valias vb; - // } - // )cpp", - // "0: targets = {valias}\n" - // "1: targets = {valias}\n"}, - + {R"cpp( + template struct vector { using value_type = T; }; + template <> struct vector { using value_type = bool; }; + template using valias = vector; + void foo() { + $0^valias vi; + $1^valias vb; + } + )cpp", + "0: targets = {valias}\n" + "1: targets = {valias}\n"}, // MemberExpr should know their using declaration. {R"cpp( struct X { void func(int); } -- 2.7.4