[PATCH] D146202: [clang] Fix a UsingTemplate regression after 3e78fa860235431323aaf08c8fa922d75a7cfffa

Haojian Wu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 16 04:59:52 PDT 2023


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG1f5fdc22a26c: [clang] Fix a UsingTemplate regression after… (authored by hokein).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146202

Files:
  clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
  clang/lib/AST/TemplateName.cpp
  clang/test/AST/ast-dump-using-template.cpp


Index: clang/test/AST/ast-dump-using-template.cpp
===================================================================
--- clang/test/AST/ast-dump-using-template.cpp
+++ clang/test/AST/ast-dump-using-template.cpp
@@ -9,8 +9,11 @@
  public:
    S(T);
 };
+template<typename T> struct S2 { S2(T); };
+template <typename T> S2(T t) -> S2<T>;
 }
 using ns::S;
+using ns::S2;
 
 // TemplateName in TemplateSpecializationType.
 template<typename T>
@@ -36,3 +39,10 @@
 // CHECK-NEXT:  |-DeclRefExpr {{.*}}
 // CHECK-NEXT:  `-ElaboratedType {{.*}} 'S<int>' sugar
 // CHECK-NEXT:    `-DeducedTemplateSpecializationType {{.*}} 'ns::S<int>' sugar using
+
+S2 DeducedTemplateSpecializationT2(123);
+using D = decltype(DeducedTemplateSpecializationT2);
+// CHECK:      DecltypeType {{.*}}
+// CHECK-NEXT:  |-DeclRefExpr {{.*}}
+// CHECK-NEXT:  `-ElaboratedType {{.*}} 'S2<int>' sugar
+// CHECK-NEXT:    `-DeducedTemplateSpecializationType {{.*}} 'S2<int>' sugar using
Index: clang/lib/AST/TemplateName.cpp
===================================================================
--- clang/lib/AST/TemplateName.cpp
+++ clang/lib/AST/TemplateName.cpp
@@ -282,7 +282,9 @@
 }
 
 void TemplateName::Profile(llvm::FoldingSetNodeID &ID) {
-  if (auto *TD = getAsTemplateDecl())
+  if (const auto* USD = getAsUsingShadowDecl())
+    ID.AddPointer(USD->getCanonicalDecl());
+  else if (const auto *TD = getAsTemplateDecl())
     ID.AddPointer(TD->getCanonicalDecl());
   else
     ID.AddPointer(Storage.getOpaqueValue());
Index: clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
===================================================================
--- clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
@@ -171,6 +171,13 @@
       namespace ns {template <typename> struct S {}; }
       using ns::$explicit^S;)cpp",
            "^S<int> x;");
+  testWalk(R"cpp(
+      namespace ns {
+        template <typename T> struct S { S(T);};
+        template <typename T> S(T t) -> S<T>;
+      }
+      using ns::$explicit^S;)cpp",
+      "^S x(123);");
   testWalk("template<typename> struct $explicit^S {};",
            R"cpp(
       template <template <typename> typename> struct X {};


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D146202.505774.patch
Type: text/x-patch
Size: 2239 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230316/bd11e015/attachment.bin>


More information about the cfe-commits mailing list