[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
This commit is contained in:
Haojian Wu 2022-04-26 09:34:46 +02:00
parent 74273d575f
commit 8052f4d22a
3 changed files with 11 additions and 0 deletions

View File

@ -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;

View File

@ -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;
}

View File

@ -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) {