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,19 @@
+
Matcher<Stmt> | cxxNoexceptExpr | Matcher<CXXNoexceptExpr>... |
+Matches noexcept expressions.
+
+Given
+ void nothrow() noexcpet;
+ void throws();
+ bool a = noexcept(nothrow())
+ bool b = noexcept(throws())
+cxxNoexceptExpr()
+ matches `noexcept(nothrow())` and `noexcept(throws())`.
+ |
+
+
Matcher<Stmt> | cxxNullPtrLiteralExpr | Matcher<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,20 @@
extern const internal::VariadicDynCastAllOfMatcher
cxxDeleteExpr;
+/// Matches noexcept expressions.
+///
+/// Given
+/// \code
+/// void nothrow() noexcpet;
+/// void throws();
+/// bool a = noexcept(nothrow())
+/// bool b = noexcept(throws())
+/// \endcode
+/// cxxNoexceptExpr()
+/// matches `noexcept(nothrow())` and `noexcept(throws())`.
+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,14 @@
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));
+}
+
TEST(Matcher, DefaultArgument) {
StatementMatcher Arg = cxxDefaultArgExpr();