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
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@325678
91177308-0d34-0410-b5e6-
96231b3b80d8
/// \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>.
///
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
"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,