diff --git a/clang/docs/LibASTMatchersReference.html b/clang/docs/LibASTMatchersReference.html --- a/clang/docs/LibASTMatchersReference.html +++ b/clang/docs/LibASTMatchersReference.html @@ -1003,6 +1003,21 @@ +Matcher<Stmt>cxxNoexceptExprMatcher<CXXNoexceptExpr>... +
Matches noexcept expressions.
+
+Given
+  bool a() noexcept;
+  bool b() noexcept(true);
+  bool c() noexcept(false);
+  bool d() noexcept(noexcept(a()));
+  bool e = noexcept(b()) || noexcept(c());
+cxxNoexceptExpr()
+  matches `noexcept(a())`, `noexcept(b())` and `noexcept(c())`.
+  doesn't match the noexcept specifier in the declarations a, b, c or d.
+
+ + Matcher<Stmt>cxxNullPtrLiteralExprMatcher<CXXNullPtrLiteralExpr>...
Matches nullptr literal.
 
diff --git a/clang/include/clang/ASTMatchers/ASTMatchers.h b/clang/include/clang/ASTMatchers/ASTMatchers.h --- a/clang/include/clang/ASTMatchers/ASTMatchers.h +++ b/clang/include/clang/ASTMatchers/ASTMatchers.h @@ -1824,6 +1824,22 @@ extern const internal::VariadicDynCastAllOfMatcher cxxDeleteExpr; +/// Matches noexcept expressions. +/// +/// Given +/// \code +/// bool a() noexcept; +/// bool b() noexcept(true); +/// bool c() noexcept(false); +/// bool d() noexcept(noexcept(a())); +/// bool e = noexcept(b()) || noexcept(c()); +/// \endcode +/// cxxNoexceptExpr() +/// matches `noexcept(a())`, `noexcept(b())` and `noexcept(c())`. +/// doesn't match the noexcept specifier in the declarations a, b, c or d. +extern const internal::VariadicDynCastAllOfMatcher + cxxNoexceptExpr; + /// Matches array subscript expressions. /// /// Given diff --git a/clang/lib/ASTMatchers/ASTMatchersInternal.cpp b/clang/lib/ASTMatchers/ASTMatchersInternal.cpp --- a/clang/lib/ASTMatchers/ASTMatchersInternal.cpp +++ b/clang/lib/ASTMatchers/ASTMatchersInternal.cpp @@ -730,6 +730,8 @@ materializeTemporaryExpr; const internal::VariadicDynCastAllOfMatcher cxxNewExpr; const internal::VariadicDynCastAllOfMatcher cxxDeleteExpr; +const internal::VariadicDynCastAllOfMatcher + cxxNoexceptExpr; const internal::VariadicDynCastAllOfMatcher arraySubscriptExpr; const internal::VariadicDynCastAllOfMatcher diff --git a/clang/lib/ASTMatchers/Dynamic/Registry.cpp b/clang/lib/ASTMatchers/Dynamic/Registry.cpp --- a/clang/lib/ASTMatchers/Dynamic/Registry.cpp +++ b/clang/lib/ASTMatchers/Dynamic/Registry.cpp @@ -183,6 +183,7 @@ REGISTER_MATCHER(cxxMemberCallExpr); REGISTER_MATCHER(cxxMethodDecl); REGISTER_MATCHER(cxxNewExpr); + REGISTER_MATCHER(cxxNoexceptExpr); REGISTER_MATCHER(cxxNullPtrLiteralExpr); REGISTER_MATCHER(cxxOperatorCallExpr); REGISTER_MATCHER(cxxRecordDecl); diff --git a/clang/lib/Analysis/ExprMutationAnalyzer.cpp b/clang/lib/Analysis/ExprMutationAnalyzer.cpp --- a/clang/lib/Analysis/ExprMutationAnalyzer.cpp +++ b/clang/lib/Analysis/ExprMutationAnalyzer.cpp @@ -43,9 +43,6 @@ return Node.isPotentiallyEvaluated(); } -const ast_matchers::internal::VariadicDynCastAllOfMatcher - cxxNoexceptExpr; - const ast_matchers::internal::VariadicDynCastAllOfMatcher genericSelectionExpr; diff --git a/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp --- a/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp +++ b/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp @@ -679,6 +679,16 @@ cxxDeleteExpr())); } +TEST(Matcher, NoexceptExpression) { + StatementMatcher NoExcept = cxxNoexceptExpr(); + EXPECT_TRUE(matches("void foo(); bool bar = noexcept(foo());", NoExcept)); + EXPECT_TRUE( + matches("void foo() noexcept; bool bar = noexcept(foo());", NoExcept)); + EXPECT_TRUE(notMatches("void foo() noexcept;", NoExcept)); + EXPECT_TRUE(notMatches("void foo() noexcept(1+1);", NoExcept)); + EXPECT_TRUE(matches("void foo() noexcept(noexcept(1+1));", NoExcept)); +} + TEST(Matcher, DefaultArgument) { StatementMatcher Arg = cxxDefaultArgExpr();