Index: docs/LibASTMatchersReference.html =================================================================== --- docs/LibASTMatchersReference.html +++ docs/LibASTMatchersReference.html @@ -3183,6 +3183,15 @@ +
Matches a declaration that has default arguments. + +Example matches y (matcher = parmVarDecl(hasDefaultArgument())) +void x(int val) {}; +void y(int val = 0) {}; +
Matches if the matched type is represented by the given string. Index: include/clang/ASTMatchers/ASTMatchers.h =================================================================== --- include/clang/ASTMatchers/ASTMatchers.h +++ include/clang/ASTMatchers/ASTMatchers.h @@ -5818,6 +5818,17 @@ return Node.hasExternalFormalLinkage(); } +/// \brief Matches a declaration that has default arguments. +/// +/// Example matches y (matcher = parmVarDecl(hasDefaultArgument())) +/// \code +/// void x(int val) {}; +/// void y(int val = 0) {}; +/// \endcode +AST_MATCHER(ParmVarDecl, hasDefaultArgument) { + return Node.hasDefaultArg(); +} + } // namespace ast_matchers } // namespace clang Index: unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp =================================================================== --- unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp +++ unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp @@ -1991,5 +1991,12 @@ namedDecl(hasExternalFormalLinkage()))); } +TEST(HasDefaultArgument, Basic) { + EXPECT_TRUE(matches("void x(int val = 0) {};", + parmVarDecl(hasDefaultArgument()))); + EXPECT_TRUE(notMatches("void x(int val) {};", + parmVarDecl(hasDefaultArgument()))); +} + } // namespace ast_matchers } // namespace clang