Izaron updated this revision to Diff 401363.
Izaron added a comment.
Fixed commit
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D117613/new/
https://reviews.llvm.org/D117613
Files:
clang/docs/LibASTMatchersReference.html
clang/include/clang/ASTMatchers/ASTMatchers.h
clang/lib/ASTMatchers/Dynamic/Registry.cpp
clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
Index: clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
===================================================================
--- clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
@@ -1790,6 +1790,32 @@
EXPECT_TRUE(matches("void f() noexcept;", functionProtoType(isNoThrow())));
}
+TEST_P(ASTMatchersTest, IsConsteval) {
+ if (!GetParam().isCXX20OrLater())
+ return;
+
+ EXPECT_TRUE(matches("consteval int bar();",
+ functionDecl(hasName("bar"), isConsteval())));
+ EXPECT_TRUE(notMatches("constexpr int bar();",
+ functionDecl(hasName("bar"), isConsteval())));
+ EXPECT_TRUE(
+ notMatches("int bar();", functionDecl(hasName("bar"), isConsteval())));
+}
+
+TEST_P(ASTMatchersTest, IsConsteval_MatchesIfConsteval) {
+ if (!GetParam().isCXX20OrLater())
+ return;
+
+ EXPECT_TRUE(matches("void baz() { if consteval {} }", ifStmt(isConsteval())));
+ EXPECT_TRUE(matches("void baz() { if ! consteval {} }", ifStmt(isConsteval())));
+ EXPECT_TRUE(matches("void baz() { if ! consteval {} else {} }", ifStmt(isConsteval())));
+ EXPECT_TRUE(matches("void baz() { if not consteval {} }", ifStmt(isConsteval())));
+ EXPECT_TRUE(notMatches("void baz() { if constexpr(1 > 0) {} }",
+ ifStmt(isConsteval())));
+ EXPECT_TRUE(
+ notMatches("void baz() { if (1 > 0) {} }", ifStmt(isConsteval())));
+}
+
TEST_P(ASTMatchersTest, IsConstexpr) {
if (!GetParam().isCXX11OrLater()) {
return;
Index: clang/lib/ASTMatchers/Dynamic/Registry.cpp
===================================================================
--- clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -404,6 +404,7 @@
REGISTER_MATCHER(isComparisonOperator);
REGISTER_MATCHER(isConst);
REGISTER_MATCHER(isConstQualified);
+ REGISTER_MATCHER(isConsteval);
REGISTER_MATCHER(isConstexpr);
REGISTER_MATCHER(isCopyAssignmentOperator);
REGISTER_MATCHER(isCopyConstructor);
Index: clang/include/clang/ASTMatchers/ASTMatchers.h
===================================================================
--- clang/include/clang/ASTMatchers/ASTMatchers.h
+++ clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -5170,6 +5170,24 @@
return FnTy->isNothrow();
}
+/// Matches consteval function declarations and if consteval.
+///
+/// Given:
+/// \code
+/// consteval int a();
+/// void b() { if consteval {} }
+/// void c() { if ! consteval {} }
+/// void d() { if ! consteval {} else {} }
+/// \endcode
+/// functionDecl(isConsteval())
+/// matches the declaration of "int a()".
+/// ifStmt(isConsteval())
+/// matches the if statement in "void b()", "void c()", "void d()".
+AST_POLYMORPHIC_MATCHER(isConsteval,
+ AST_POLYMORPHIC_SUPPORTED_TYPES(FunctionDecl, IfStmt)) {
+ return Node.isConsteval();
+}
+
/// Matches constexpr variable and function declarations,
/// and if constexpr.
///
Index: clang/docs/LibASTMatchersReference.html
===================================================================
--- clang/docs/LibASTMatchersReference.html
+++ clang/docs/LibASTMatchersReference.html
@@ -4201,6 +4201,21 @@
</pre></td></tr>
+<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>></td><td class="name" onclick="toggle('isConsteval1')"><a name="isConsteval1Anchor">isConsteval</a></td><td></td></tr>
+<tr><td colspan="4" class="doc" id="isConsteval1"><pre>Matches consteval function declarations and if consteval.
+
+Given:
+ consteval int a();
+ void b() { if consteval {} }
+ void c() { if ! consteval {} }
+ void d() { if ! consteval {} else {} }
+functionDecl(isConsteval())
+ matches the declaration of "int a()".
+ifStmt(isConsteval())
+ matches the if statement in "void b()", "void c()", "void d()".
+</pre></td></tr>
+
+
<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>></td><td class="name" onclick="toggle('isConstexpr1')"><a name="isConstexpr1Anchor">isConstexpr</a></td><td></td></tr>
<tr><td colspan="4" class="doc" id="isConstexpr1"><pre>Matches constexpr variable and function declarations,
and if constexpr.
@@ -4473,6 +4488,21 @@
</pre></td></tr>
+<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1IfStmt.html">IfStmt</a>></td><td class="name" onclick="toggle('isConsteval2')"><a name="isConsteval2Anchor">isConsteval</a></td><td></td></tr>
+<tr><td colspan="4" class="doc" id="isConsteval2"><pre>Matches consteval function declarations and if consteval.
+
+Given:
+ consteval int a();
+ void b() { if consteval {} }
+ void c() { if ! consteval {} }
+ void d() { if ! consteval {} else {} }
+functionDecl(isConsteval())
+ matches the declaration of "int a()".
+ifStmt(isConsteval())
+ matches the if statement in "void b()", "void c()", "void d()".
+</pre></td></tr>
+
+
<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1IfStmt.html">IfStmt</a>></td><td class="name" onclick="toggle('isConstexpr2')"><a name="isConstexpr2Anchor">isConstexpr</a></td><td></td></tr>
<tr><td colspan="4" class="doc" id="isConstexpr2"><pre>Matches constexpr variable and function declarations,
and if constexpr.
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits