r325678 - [ASTMatchers] isTemplateInstantiation: also match explicit instantiation declaration.

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 21 05:54:29 PST 2018


On Wed, Feb 21, 2018 at 8:51 AM, Eric Liu via cfe-commits
<cfe-commits at lists.llvm.org> wrote:
> Author: ioeric
> Date: Wed Feb 21 05:51:27 2018
> New Revision: 325678
>
> URL: http://llvm.org/viewvc/llvm-project?rev=325678&view=rev
> Log:
> [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
>
> Modified:
>     cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
>     cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp

Please regenerate the AST matcher documentation as well.

~Aaron

>
> Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h?rev=325678&r1=325677&r2=325678&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h (original)
> +++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h Wed Feb 21 05:51:27 2018
> @@ -4649,6 +4649,10 @@ AST_MATCHER_P(UsingShadowDecl, hasTarget
>  /// \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(isTemplateInstan
>                                                          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
>
> Modified: cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp?rev=325678&r1=325677&r2=325678&view=diff
> ==============================================================================
> --- cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp (original)
> +++ cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp Wed Feb 21 05:51:27 2018
> @@ -1623,6 +1623,14 @@ TEST(IsTemplateInstantiation, MatchesExp
>        "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,
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


More information about the cfe-commits mailing list