</pre></td></tr>\r
\r
\r
+<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>></td><td class="name" onclick="toggle('isVariadic0')"><a name="isVariadic0Anchor">isVariadic</a></td><td></td></tr>\r
+<tr><td colspan="4" class="doc" id="isVariadic0"><pre>Matches if a function declaration is variadic.\r
+\r
+Example matches f, but not g or h. The function i will not match, event when\r
+compiled in C mode.\r
+ void f(...);\r
+ void g(int);\r
+ template <typename... Ts> void h(Ts...);\r
+ void i();\r
+</pre></td></tr>\r
+\r
+\r
<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>></td><td class="name" onclick="toggle('parameterCountIs0')"><a name="parameterCountIs0Anchor">parameterCountIs</a></td><td>unsigned N</td></tr>\r
<tr><td colspan="4" class="doc" id="parameterCountIs0"><pre>Matches FunctionDecls that have a specific parameter count.\r
\r
return Node.isThisDeclarationADefinition();
}
+/// \brief Matches if a function declaration is variadic.
+///
+/// Example matches f, but not g or h. The function i will not match, even when
+/// compiled in C mode.
+/// \code
+/// void f(...);
+/// void g(int);
+/// template <typename... Ts> void h(Ts...);
+/// void i();
+/// \endcode
+AST_MATCHER(FunctionDecl, isVariadic) {
+ return Node.isVariadic();
+}
+
/// \brief Matches the class declaration that the given method declaration
/// belongs to.
///
REGISTER_MATCHER(isStruct);
REGISTER_MATCHER(isTemplateInstantiation);
REGISTER_MATCHER(isUnion);
+ REGISTER_MATCHER(isVariadic);
REGISTER_MATCHER(isVirtual);
REGISTER_MATCHER(isWritten);
REGISTER_MATCHER(labelStmt);
notMatches("void f(int);"
"template <typename T> struct S { void g(T t) { f(t); } };",
CallFunctionF));
+
+ EXPECT_TRUE(matches("void f(...);", functionDecl(isVariadic())));
+ EXPECT_TRUE(notMatches("void f(int);", functionDecl(isVariadic())));
+ EXPECT_TRUE(notMatches("template <typename... Ts> void f(Ts...);",
+ functionDecl(isVariadic())));
+ EXPECT_TRUE(notMatches("void f();", functionDecl(isVariadic())));
+ EXPECT_TRUE(notMatchesC("void f();", functionDecl(isVariadic())));
}
TEST(FunctionTemplate, MatchesFunctionTemplateDeclarations) {
"input.c");
}
+template <typename T>
+testing::AssertionResult notMatchesC(const std::string &Code,
+ const T &AMatcher) {
+ return matchesConditionally(Code, AMatcher, false, "", FileContentMappings(),
+ "input.c");
+}
+
template <typename T>
testing::AssertionResult notMatchesObjC(const std::string &Code,
const T &AMatcher) {