[PATCH] D68124: [clangd] Fix template type aliases in findExplicitReference

Phabricator via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 27 10:54:04 PDT 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rL373104: [clangd] Fix template type aliases in findExplicitReference (authored by ibiryukov, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D68124?vs=222204&id=222207#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D68124/new/

https://reviews.llvm.org/D68124

Files:
  clang-tools-extra/trunk/clangd/FindTarget.cpp
  clang-tools-extra/trunk/clangd/unittests/FindTargetTests.cpp


Index: clang-tools-extra/trunk/clangd/FindTarget.cpp
===================================================================
--- clang-tools-extra/trunk/clangd/FindTarget.cpp
+++ clang-tools-extra/trunk/clangd/FindTarget.cpp
@@ -477,13 +477,6 @@
       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 @@
     }
 
     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 <class T> using valias = vector<T>;
+      //    ^valias<int> x;
+      // 'explicitReferenceTargets' will return:
+      //    1. valias with mask 'Alias'.
+      //    2. 'vector<int>' 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(
Index: clang-tools-extra/trunk/clangd/unittests/FindTargetTests.cpp
===================================================================
--- clang-tools-extra/trunk/clangd/unittests/FindTargetTests.cpp
+++ clang-tools-extra/trunk/clangd/unittests/FindTargetTests.cpp
@@ -615,20 +615,18 @@
         )cpp",
            "0: targets = {vector<int>}\n"
            "1: targets = {vector<bool>}\n"},
-          // FIXME: Fix 'allTargetDecls' to return alias template and re-enable.
           // Template type aliases.
-          //   {R"cpp(
-          //   template <class T> struct vector { using value_type = T; };
-          //   template <> struct vector<bool> { using value_type = bool; };
-          //   template <class T> using valias = vector<T>;
-          //   void foo() {
-          //     $0^valias<int> vi;
-          //     $1^valias<bool> vb;
-          //   }
-          // )cpp",
-          //    "0: targets = {valias}\n"
-          //    "1: targets = {valias}\n"},
-
+          {R"cpp(
+            template <class T> struct vector { using value_type = T; };
+            template <> struct vector<bool> { using value_type = bool; };
+            template <class T> using valias = vector<T>;
+            void foo() {
+              $0^valias<int> vi;
+              $1^valias<bool> vb;
+            }
+          )cpp",
+           "0: targets = {valias}\n"
+           "1: targets = {valias}\n"},
           // MemberExpr should know their using declaration.
           {R"cpp(
             struct X { void func(int); }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D68124.222207.patch
Type: text/x-patch
Size: 3437 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190927/b36268d5/attachment.bin>


More information about the cfe-commits mailing list