Index: docs/LibASTMatchersReference.html =================================================================== --- docs/LibASTMatchersReference.html +++ docs/LibASTMatchersReference.html @@ -2371,6 +2371,22 @@ +
Matches functions that have a dynamic exception specification. + +Given: + void f(); + void g() noexcept; + void h() noexcept(true); + void i() noexcept(false); + void j() throw(); + void k() throw(int); + void l() throw(...); +functionDecl(hasDynamicExceptionSpec()) + matches the declarations of j, k, and l, but not f, g, h, or i. +
Matches overloaded operator names. Index: include/clang/ASTMatchers/ASTMatchers.h =================================================================== --- include/clang/ASTMatchers/ASTMatchers.h +++ include/clang/ASTMatchers/ASTMatchers.h @@ -3212,6 +3212,26 @@ return Node.isDefaulted(); } +/// \brief Matches functions that have a dynamic exception specification. +/// +/// Given: +/// \code +/// void f(); +/// void g() noexcept; +/// void h() noexcept(true); +/// void i() noexcept(false); +/// void j() throw(); +/// void k() throw(int); +/// void l() throw(...); +/// \endcode +/// functionDecl(hasDynamicExceptionSpec()) +/// matches the declarations of j, k, and l, but not f, g, h, or i. +AST_MATCHER(FunctionDecl, hasDynamicExceptionSpec) { + if (const auto *FnTy = Node.getType()->getAs()) + return FnTy->hasDynamicExceptionSpec(); + return false; +} + /// \brief Matches functions that have a non-throwing exception specification. /// /// Given: Index: lib/ASTMatchers/Dynamic/Registry.cpp =================================================================== --- lib/ASTMatchers/Dynamic/Registry.cpp +++ lib/ASTMatchers/Dynamic/Registry.cpp @@ -218,6 +218,7 @@ REGISTER_MATCHER(hasDeducedType); REGISTER_MATCHER(hasDescendant); REGISTER_MATCHER(hasDestinationType); + REGISTER_MATCHER(hasDynamicExceptionSpec); REGISTER_MATCHER(hasEitherOperand); REGISTER_MATCHER(hasElementType); REGISTER_MATCHER(hasElse); Index: unittests/ASTMatchers/ASTMatchersTest.cpp =================================================================== --- unittests/ASTMatchers/ASTMatchersTest.cpp +++ unittests/ASTMatchers/ASTMatchersTest.cpp @@ -3552,6 +3552,22 @@ pointsTo(TypeMatcher(anything())))))); } +TEST(hasDynamicExceptionSpec, MatchesDynamicExceptionSpecifications) { + EXPECT_TRUE(notMatches("void f();", functionDecl(hasDynamicExceptionSpec()))); + EXPECT_TRUE(notMatches("void g() noexcept;", + functionDecl(hasDynamicExceptionSpec()))); + EXPECT_TRUE(notMatches("void h() noexcept(true);", + functionDecl(hasDynamicExceptionSpec()))); + EXPECT_TRUE(notMatches("void i() noexcept(false);", + functionDecl(hasDynamicExceptionSpec()))); + EXPECT_TRUE( + matches("void j() throw();", functionDecl(hasDynamicExceptionSpec()))); + EXPECT_TRUE( + matches("void k() throw(int);", functionDecl(hasDynamicExceptionSpec()))); + EXPECT_TRUE( + matches("void l() throw(...);", functionDecl(hasDynamicExceptionSpec()))); +} + TEST(HasImplicitDestinationType, MatchesSimpleCase) { // This test creates an implicit const cast. EXPECT_TRUE(matches("int x; const int i = x;",