[cfe-commits] [PATCH] AST Matchers: function and class template matchers

Manuel Klimek klimek at google.com
Fri Aug 17 10:58:28 PDT 2012


Hi Dmitri,

thanks for the patch!

@@ -385,7 +393,15 @@
 ///   void f();
 const internal::VariadicDynCastAllOfMatcher<Decl, FunctionDecl> function;

+/// \brief Matches C++ function template declarations.
+///
+/// Example matches f
+///   template<class T> void f(T t) {}
+const internal::VariadicDynCastAllOfMatcher<
+  Decl,
+  FunctionTemplateDecl> functionTemplate;

+

Any reason for the additional newline?

+TEST(DeclarationMatcher, MatchClassTemplate) {
+  DeclarationMatcher ClassX = classTemplate(hasName("X"));
+  EXPECT_TRUE(notMatches("", ClassX));

I don't think we need to test this  - or do you think it provides any
information (one problem is that there is some stuff that's declared
by default, but it depends on the system we compile on etc).

+  EXPECT_TRUE(notMatches("class X;", ClassX));
+  EXPECT_TRUE(notMatches("class X {};", ClassX));
+  EXPECT_TRUE(matches("template<class T> class X {};", ClassX));
+  EXPECT_TRUE(notMatches("template<class T> class X { };"
+                         "template<> class X<int> { int a; };",
+              classTemplate(hasName("X"),
hasDescendant(field(hasName("a"))))));
+}
+

Can you split up this test much like the other tests below (which are
great!). I know that not all the tests currently follow the correct
style, but I'd like us to not introduce any new ones there...
(What I mean is: have multiple TEST(ClassTemplate, Matches... or
DoesNotMatch...))

Thanks!
/Manuel


On Fri, Aug 17, 2012 at 7:47 PM, Dmitri Gribenko <gribozavr at gmail.com> wrote:
> Hello,
>
> The attached patch introduces functionTemplate(), classTemplate() and
> isExplicitTemplateSpecialization() matchers which do what their name
> says.
>
> Please review.
>
> Dmitri
>
> --
> main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
> (j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr at gmail.com>*/



More information about the cfe-commits mailing list