[clang] 8052f4d - [AST] Consider QualifiedTemplateName in TemplateName::getAsUsingDecl().
Haojian Wu via cfe-commits
cfe-commits at lists.llvm.org
Wed Apr 27 05:16:29 PDT 2022
Author: Haojian Wu
Date: 2022-04-27T14:16:19+02:00
New Revision: 8052f4d22a12f1baa949c7a04f029e231faae90a
URL: https://github.com/llvm/llvm-project/commit/8052f4d22a12f1baa949c7a04f029e231faae90a
DIFF: https://github.com/llvm/llvm-project/commit/8052f4d22a12f1baa949c7a04f029e231faae90a.diff
LOG: [AST] Consider QualifiedTemplateName in TemplateName::getAsUsingDecl().
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.
Differential Revision: https://reviews.llvm.org/D124437
Added:
Modified:
clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
clang/lib/AST/TemplateName.cpp
clang/unittests/AST/TemplateNameTest.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp b/clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
index 8df292cd28a9..77d4e289cf26 100644
--- a/clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
+++ b/clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
@@ -90,6 +90,14 @@ TEST(IncludeCleaner, ReferencedLocations) {
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;
diff --git a/clang/lib/AST/TemplateName.cpp b/clang/lib/AST/TemplateName.cpp
index f0f64cd5a516..11dc3d2e1985 100644
--- a/clang/lib/AST/TemplateName.cpp
+++ b/clang/lib/AST/TemplateName.cpp
@@ -172,6 +172,8 @@ UsingShadowDecl *TemplateName::getAsUsingShadowDecl() const {
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;
}
diff --git a/clang/unittests/AST/TemplateNameTest.cpp b/clang/unittests/AST/TemplateNameTest.cpp
index 5844af6cc957..fb9061053ea5 100644
--- a/clang/unittests/AST/TemplateNameTest.cpp
+++ b/clang/unittests/AST/TemplateNameTest.cpp
@@ -82,6 +82,7 @@ TEST(TemplateName, QualifiedUsingTemplate) {
const auto *USD = QTN->getUnderlyingTemplate().getAsUsingShadowDecl();
EXPECT_TRUE(USD);
EXPECT_EQ(USD->getTargetDecl(), TN.getAsTemplateDecl());
+ EXPECT_EQ(TN.getAsUsingShadowDecl(), USD);
}
TEST(TemplateName, UsingTemplate) {
More information about the cfe-commits
mailing list