Skip to content

Commit 8052f4d

Browse files
committed
[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
1 parent 74273d5 commit 8052f4d

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,14 @@ TEST(IncludeCleaner, ReferencedLocations) {
9090
template <template <typename> class T> class X {};
9191
X<A> x;
9292
)cpp"},
93+
{R"cpp(
94+
namespace ns { template<typename T> class A {}; }
95+
namespace absl {using ns::^A;}
96+
)cpp",
97+
R"cpp(
98+
template <template <typename> class T> class X {};
99+
X<absl::A> x;
100+
)cpp"},
93101
{R"cpp(
94102
namespace ns { template<typename T> struct ^A { ^A(T); }; }
95103
using ns::^A;

clang/lib/AST/TemplateName.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ UsingShadowDecl *TemplateName::getAsUsingShadowDecl() const {
172172
if (Decl *D = Storage.dyn_cast<Decl *>())
173173
if (UsingShadowDecl *USD = dyn_cast<UsingShadowDecl>(D))
174174
return USD;
175+
if (QualifiedTemplateName *QTN = getAsQualifiedTemplateName())
176+
return QTN->getUnderlyingTemplate().getAsUsingShadowDecl();
175177
return nullptr;
176178
}
177179

clang/unittests/AST/TemplateNameTest.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ TEST(TemplateName, QualifiedUsingTemplate) {
8282
const auto *USD = QTN->getUnderlyingTemplate().getAsUsingShadowDecl();
8383
EXPECT_TRUE(USD);
8484
EXPECT_EQ(USD->getTargetDecl(), TN.getAsTemplateDecl());
85+
EXPECT_EQ(TN.getAsUsingShadowDecl(), USD);
8586
}
8687

8788
TEST(TemplateName, UsingTemplate) {

0 commit comments

Comments
 (0)