Index: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h =================================================================== --- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h +++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h @@ -4649,6 +4649,10 @@ /// \code /// template class X {}; class A {}; template class X; /// \endcode +/// or +/// \code +/// template class X {}; class A {}; extern template class X; +/// \endcode /// cxxRecordDecl(hasName("::X"), isTemplateInstantiation()) /// matches the template instantiation of X. /// @@ -4666,7 +4670,9 @@ 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 Index: cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp =================================================================== --- cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp +++ cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp @@ -1623,6 +1623,14 @@ "template class X;", 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 class X { void f() { T t; } };" + "extern template class X;", + cxxRecordDecl(isTemplateInstantiation(), + unless(hasDescendant(varDecl(hasName("t"))))))); } TEST(IsTemplateInstantiation,