[clang] aec6210 - [ASTMatchers] Add cxxNoexceptExpr AST matcher
via cfe-commits
cfe-commits at lists.llvm.org
Tue Jan 28 05:12:36 PST 2020
Author: Nathan
Date: 2020-01-28T13:12:28Z
New Revision: aec6210367de714caf876fe19c4b475889890e21
URL: https://github.com/llvm/llvm-project/commit/aec6210367de714caf876fe19c4b475889890e21
DIFF: https://github.com/llvm/llvm-project/commit/aec6210367de714caf876fe19c4b475889890e21.diff
LOG: [ASTMatchers] Add cxxNoexceptExpr AST matcher
Summary: Adds a cxxNoexceptExpr matcher that matches the [[ https://en.cppreference.com/w/cpp/language/noexcept | noexcept operator ]].
Reviewers: aaron.ballman
Reviewed By: aaron.ballman
Subscribers: merge_guards_bot, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D73439
Added:
Modified:
clang/docs/LibASTMatchersReference.html
clang/include/clang/ASTMatchers/ASTMatchers.h
clang/lib/ASTMatchers/ASTMatchersInternal.cpp
clang/lib/ASTMatchers/Dynamic/Registry.cpp
clang/lib/Analysis/ExprMutationAnalyzer.cpp
clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
Removed:
################################################################################
diff --git a/clang/docs/LibASTMatchersReference.html b/clang/docs/LibASTMatchersReference.html
index bc6501c767ef..837f74ea0d41 100644
--- a/clang/docs/LibASTMatchersReference.html
+++ b/clang/docs/LibASTMatchersReference.html
@@ -1003,6 +1003,21 @@ <h2 id="decl-matchers">Node Matchers</h2>
</pre></td></tr>
+<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('cxxNoexceptExpr0')"><a name="cxxNoexceptExpr0Anchor">cxxNoexceptExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXNoexceptExpr.html">CXXNoexceptExpr</a>>...</td></tr>
+<tr><td colspan="4" class="doc" id="cxxNoexceptExpr0"><pre>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.
+</pre></td></tr>
+
+
<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('cxxNullPtrLiteralExpr0')"><a name="cxxNullPtrLiteralExpr0Anchor">cxxNullPtrLiteralExpr</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXNullPtrLiteralExpr.html">CXXNullPtrLiteralExpr</a>>...</td></tr>
<tr><td colspan="4" class="doc" id="cxxNullPtrLiteralExpr0"><pre>Matches nullptr literal.
</pre></td></tr>
diff --git a/clang/include/clang/ASTMatchers/ASTMatchers.h b/clang/include/clang/ASTMatchers/ASTMatchers.h
index 538babc569e9..2e932dbf3daa 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchers.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -1824,6 +1824,22 @@ extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXNewExpr> cxxNewExpr;
extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXDeleteExpr>
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<Stmt, CXXNoexceptExpr>
+ cxxNoexceptExpr;
+
/// Matches array subscript expressions.
///
/// Given
diff --git a/clang/lib/ASTMatchers/ASTMatchersInternal.cpp b/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
index e08765b75665..3631922a5abf 100644
--- a/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
+++ b/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
@@ -730,6 +730,8 @@ const internal::VariadicDynCastAllOfMatcher<Stmt, MaterializeTemporaryExpr>
materializeTemporaryExpr;
const internal::VariadicDynCastAllOfMatcher<Stmt, CXXNewExpr> cxxNewExpr;
const internal::VariadicDynCastAllOfMatcher<Stmt, CXXDeleteExpr> cxxDeleteExpr;
+const internal::VariadicDynCastAllOfMatcher<Stmt, CXXNoexceptExpr>
+ cxxNoexceptExpr;
const internal::VariadicDynCastAllOfMatcher<Stmt, ArraySubscriptExpr>
arraySubscriptExpr;
const internal::VariadicDynCastAllOfMatcher<Stmt, CXXDefaultArgExpr>
diff --git a/clang/lib/ASTMatchers/Dynamic/Registry.cpp b/clang/lib/ASTMatchers/Dynamic/Registry.cpp
index 1c0930c5983a..67b61d064cb4 100644
--- a/clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ b/clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -183,6 +183,7 @@ RegistryMaps::RegistryMaps() {
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
index fb5a139e82ab..b09be4317851 100644
--- a/clang/lib/Analysis/ExprMutationAnalyzer.cpp
+++ b/clang/lib/Analysis/ExprMutationAnalyzer.cpp
@@ -43,9 +43,6 @@ AST_MATCHER(CXXTypeidExpr, isPotentiallyEvaluated) {
return Node.isPotentiallyEvaluated();
}
-const ast_matchers::internal::VariadicDynCastAllOfMatcher<Stmt, CXXNoexceptExpr>
- cxxNoexceptExpr;
-
const ast_matchers::internal::VariadicDynCastAllOfMatcher<Stmt,
GenericSelectionExpr>
genericSelectionExpr;
diff --git a/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
index 02514f77afd3..b37ec2705406 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -679,6 +679,16 @@ TEST(Matcher, DeleteExpression) {
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();
More information about the cfe-commits
mailing list