diff options
author | Eric Liu <ioeric@google.com> | 2018-02-21 13:51:27 +0000 |
---|---|---|
committer | Eric Liu <ioeric@google.com> | 2018-02-21 13:51:27 +0000 |
commit | 500e126155299db89682b74b7ad434c06d6ee5db (patch) | |
tree | 0da2367827c9733b723408467508179acc5e92ee | |
parent | 770397f4cdcfbf2c0e0a9604a4d6065063197317 (diff) | |
download | bcm5719-llvm-500e126155299db89682b74b7ad434c06d6ee5db.tar.gz bcm5719-llvm-500e126155299db89682b74b7ad434c06d6ee5db.zip |
[ASTMatchers] isTemplateInstantiation: also match explicit instantiation declaration.
Summary:
Example:
template <typename T> class X {}; class A {};
// Explicit instantiation declaration.
extern template class X<A>;
Reviewers: bkramer
Subscribers: klimek, cfe-commits
Differential Revision: https://reviews.llvm.org/D43567
llvm-svn: 325678
-rw-r--r-- | clang/include/clang/ASTMatchers/ASTMatchers.h | 8 | ||||
-rw-r--r-- | clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp | 8 |
2 files changed, 15 insertions, 1 deletions
diff --git a/clang/include/clang/ASTMatchers/ASTMatchers.h b/clang/include/clang/ASTMatchers/ASTMatchers.h index e51ce4175e7..b9ce2862942 100644 --- a/clang/include/clang/ASTMatchers/ASTMatchers.h +++ b/clang/include/clang/ASTMatchers/ASTMatchers.h @@ -4649,6 +4649,10 @@ AST_MATCHER_P(UsingShadowDecl, hasTargetDecl, /// \code /// template <typename T> class X {}; class A {}; template class X<A>; /// \endcode +/// or +/// \code +/// template <typename T> class X {}; class A {}; extern template class X<A>; +/// \endcode /// cxxRecordDecl(hasName("::X"), isTemplateInstantiation()) /// matches the template instantiation of X<A>. /// @@ -4666,7 +4670,9 @@ AST_POLYMORPHIC_MATCHER(isTemplateInstantiation, CXXRecordDecl)) { return (Node.getTemplateSpecializationKind() == TSK_ImplicitInstantiation || Node.getTemplateSpecializationKind() == - TSK_ExplicitInstantiationDefinition); + TSK_ExplicitInstantiationDefinition || + Node.getTemplateSpecializationKind() == + TSK_ExplicitInstantiationDeclaration); } /// \brief Matches declarations that are template instantiations or are inside diff --git a/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp index 55c53e66ecd..3e27948db78 100644 --- a/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp +++ b/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp @@ -1623,6 +1623,14 @@ TEST(IsTemplateInstantiation, MatchesExplicitClassTemplateInstantiation) { "template class X<A>;", cxxRecordDecl(isTemplateInstantiation(), hasDescendant( fieldDecl(hasType(recordDecl(hasName("A")))))))); + + // Make sure that we match the instantiation instead of the template + // definition by checking whether the member function is present. + EXPECT_TRUE( + matches("template <typename T> class X { void f() { T t; } };" + "extern template class X<int>;", + cxxRecordDecl(isTemplateInstantiation(), + unless(hasDescendant(varDecl(hasName("t"))))))); } TEST(IsTemplateInstantiation, |