[PATCH] D124437: [AST] Consider QualifiedTemplateName in TemplateName::getAsUsingDecl().

Haojian Wu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 26 00:36:57 PDT 2022


hokein created this revision.
hokein added a reviewer: sammccall.
Herald added subscribers: usaxena95, kadircet, arphaman.
Herald added a project: All.
hokein requested review of this revision.
Herald added projects: clang, clang-tools-extra.

If the underlying template name of a qualified template name is a using
decl, TemplateName::getAsUsingDecl() will return it.

This will make the UsingTemplateName consumer life easier.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D124437

Files:
  clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
  clang/lib/AST/TemplateName.cpp
  clang/unittests/AST/TemplateNameTest.cpp


Index: clang/unittests/AST/TemplateNameTest.cpp
===================================================================
--- clang/unittests/AST/TemplateNameTest.cpp
+++ clang/unittests/AST/TemplateNameTest.cpp
@@ -82,6 +82,7 @@
   const auto *USD = QTN->getUnderlyingTemplate().getAsUsingShadowDecl();
   EXPECT_TRUE(USD);
   EXPECT_EQ(USD->getTargetDecl(), TN.getAsTemplateDecl());
+  EXPECT_EQ(TN.getAsUsingShadowDecl(), USD);
 }
 
 TEST(TemplateName, UsingTemplate) {
Index: clang/lib/AST/TemplateName.cpp
===================================================================
--- clang/lib/AST/TemplateName.cpp
+++ clang/lib/AST/TemplateName.cpp
@@ -172,6 +172,8 @@
   if (Decl *D = Storage.dyn_cast<Decl *>())
     if (UsingShadowDecl *USD = dyn_cast<UsingShadowDecl>(D))
       return USD;
+  if (QualifiedTemplateName *QTN = getAsQualifiedTemplateName())
+    return QTN->getUnderlyingTemplate().getAsUsingShadowDecl();
   return nullptr;
 }
 
Index: clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
+++ clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
@@ -90,6 +90,13 @@
           template <template <typename> class T> class X {};
           X<A> x;
         )cpp"},
+      {R"cpp(namespace ns { template<typename T> class A {};
+         namespace absl {using ns::^A;}
+       )cpp",
+       R"cpp(
+          template <template <typename> class T> class X {};
+          X<absl::A> x;
+       )cpp"},
       {R"cpp(
           namespace ns { template<typename T> struct ^A { ^A(T); }; }
           using ns::^A;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D124437.425138.patch
Type: text/x-patch
Size: 1668 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220426/309f1271/attachment.bin>


More information about the cfe-commits mailing list