[clang-tools-extra] 1f5fdc2 - [clang] Fix a UsingTemplate regression after 3e78fa860235431323aaf08c8fa922d75a7cfffa
Haojian Wu via cfe-commits
cfe-commits at lists.llvm.org
Thu Mar 16 04:59:38 PDT 2023
Author: Haojian Wu
Date: 2023-03-16T12:59:26+01:00
New Revision: 1f5fdc22a26c46a11ce406b745291b3c03bc67e8
URL: https://github.com/llvm/llvm-project/commit/1f5fdc22a26c46a11ce406b745291b3c03bc67e8
DIFF: https://github.com/llvm/llvm-project/commit/1f5fdc22a26c46a11ce406b745291b3c03bc67e8.diff
LOG: [clang] Fix a UsingTemplate regression after 3e78fa860235431323aaf08c8fa922d75a7cfffa
TemplateName::getAsTemplateDecl() returns the underlying TemplateDecl
for a UsingTemplate kind template name. We should respect that in the
Profile method otherwise we might desugar the template name unexpectedly
(e.g. for template argument deduction with deduciton guides).
Differential Revision: https://reviews.llvm.org/D146202
Added:
Modified:
clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
clang/lib/AST/TemplateName.cpp
clang/test/AST/ast-dump-using-template.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp b/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
index 7dcbf475e9869..68b6b217a2e01 100644
--- a/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
+++ b/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
@@ -171,6 +171,13 @@ TEST(WalkAST, TemplateNames) {
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 {};
diff --git a/clang/lib/AST/TemplateName.cpp b/clang/lib/AST/TemplateName.cpp
index 76f507ba26fe4..2f0e4181e9408 100644
--- a/clang/lib/AST/TemplateName.cpp
+++ b/clang/lib/AST/TemplateName.cpp
@@ -282,7 +282,9 @@ bool TemplateName::containsUnexpandedParameterPack() const {
}
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());
diff --git a/clang/test/AST/ast-dump-using-template.cpp b/clang/test/AST/ast-dump-using-template.cpp
index da18f0499f54d..de3ce277fd24f 100644
--- a/clang/test/AST/ast-dump-using-template.cpp
+++ b/clang/test/AST/ast-dump-using-template.cpp
@@ -9,8 +9,11 @@ template<typename T> class S {
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 @@ using C = decltype(DeducedTemplateSpecializationT);
// 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
More information about the cfe-commits
mailing list