[PATCH] D8149: Add hasUnderlyingType narrowing matcher for TypedefDecls, functionProtoType matcher for FunctionProtoType nodes, extend parameterCountIs to FunctionProtoType nodes

Richard via cfe-commits cfe-commits at lists.llvm.org
Wed Dec 30 12:25:36 PST 2015


LegalizeAdulthood marked an inline comment as done.

================
Comment at: include/clang/ASTMatchers/ASTMatchers.h:4022
@@ +4021,3 @@
+/// functionProtoType()
+///   matches "int (*f)(int)" and the type of "g".
+AST_TYPE_MATCHER(FunctionProtoType, functionProtoType);
----------------
aaron.ballman wrote:
> Will this match g() in C mode?
No, because it doesn't declare g as a prototype.  To declare it as a prototype, it needs to be written

`void g(void);`


================
Comment at: unittests/ASTMatchers/ASTMatchersTest.cpp:4988
@@ +4987,3 @@
+  EXPECT_TRUE(matches("typedef int hasUnderlyingTypeTest;",
+                      typedefDecl(hasUnderlyingType(asString("int")))));
+}
----------------
aaron.ballman wrote:
> Can we have a test for:
> ```
> EXPECT_TRUE(matches("typedef int foo; typedef foo bar;", typedefDecl(hasUnderlyingType(asString("int")), hasName("bar"))));
> ```
> (I assume that this should work?)
This passes:

  EXPECT_TRUE(
      matches("typedef int foo; typedef foo bar;",
              typedefDecl(hasUnderlyingType(asString("foo")), hasName("bar"))));

but this does not:

  EXPECT_TRUE(
      matches("typedef int foo; typedef foo bar;",
              typedefDecl(hasUnderlyingType(asString("int")), hasName("bar"))));

I'm not really sure why; I expected that `Node.getUnderlyingType()` would return `int`, not `foo`.


http://reviews.llvm.org/D8149





More information about the cfe-commits mailing list