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

Eric Liu via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 21 05:56:02 PST 2018


Oops, I only saw this after landing the patch. I'll send another one to
update the doc. Sorry about that!

On Wed, Feb 21, 2018 at 2:54 PM Aaron Ballman <aaron at aaronballman.com>
wrote:

> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180221/a7d22091/attachment.html>


More information about the cfe-commits mailing list