xazax.hun updated this revision to Diff 145370. xazax.hun added a comment. - Rerun script
https://reviews.llvm.org/D46233 Files: docs/LibASTMatchersReference.html include/clang/ASTMatchers/ASTMatchers.h unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
Index: unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp =================================================================== --- unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp +++ unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp @@ -894,6 +894,10 @@ varDecl(hasName("foo"), isConstexpr()))); EXPECT_TRUE(matches("constexpr int bar();", functionDecl(hasName("bar"), isConstexpr()))); + EXPECT_TRUE(matchesConditionally("void baz() { if constexpr(1 > 0) {} }", + ifStmt(isConstexpr()), true, "-std=c++17")); + EXPECT_TRUE(matchesConditionally("void baz() { if (1 > 0) {} }", + ifStmt(isConstexpr()), false, "-std=c++17")); } TEST(TemplateArgumentCountIs, Matches) { Index: include/clang/ASTMatchers/ASTMatchers.h =================================================================== --- include/clang/ASTMatchers/ASTMatchers.h +++ include/clang/ASTMatchers/ASTMatchers.h @@ -3763,20 +3763,25 @@ return FnTy->isNothrow(Finder->getASTContext()); } -/// \brief Matches constexpr variable and function declarations. +/// \brief Matches constexpr variable and function declarations, +/// and if constexpr. /// /// Given: /// \code /// constexpr int foo = 42; /// constexpr int bar(); +/// void baz() { if constexpr(1 > 0) {} } /// \endcode /// varDecl(isConstexpr()) /// matches the declaration of foo. /// functionDecl(isConstexpr()) /// matches the declaration of bar. +/// ifStmt(isConstexpr()) +/// matches the if statement in baz. AST_POLYMORPHIC_MATCHER(isConstexpr, AST_POLYMORPHIC_SUPPORTED_TYPES(VarDecl, - FunctionDecl)) { + FunctionDecl, + IfStmt)) { return Node.isConstexpr(); } Index: docs/LibASTMatchersReference.html =================================================================== --- docs/LibASTMatchersReference.html +++ docs/LibASTMatchersReference.html @@ -1926,15 +1926,16 @@ </pre></td></tr> -<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1BinaryOperator.html">BinaryOperator</a>></td><td class="name" onclick="toggle('isAssignmentOperator0')"><a name="isAssignmentOperator0Anchor">isAssignmentOperator</a></td></tr> -<tr><td colspan="4" class="doc" id="isAssignmentOperator0"><pre>Matches all kinds of assignment operators. +<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1BinaryOperator.html">BinaryOperator</a>></td><td class="name" onclick="toggle('isAssignmentOperator0')"><a name="isAssignmentOperator0Anchor">isAssignmentOperator</a></td><td></td></tr> +<tr><td colspan="4" class="doc" id="isAssignmentOperator0"><pre>Matches on all kinds of assignment operators. Example 1: matches a += b (matcher = binaryOperator(isAssignmentOperator())) if (a == b) a += b; -Example 2: matches s1 = s2 (matcher = cxxOperatorCallExpr(isAssignmentOperator())) - struct S { S& operator=(const S&); }; +Example 2: matches s1 = s2 + (matcher = cxxOperatorCallExpr(isAssignmentOperator())) + struct S { S& operator=(const S&); }; void x() { S s1, s2; s1 = s2; }) </pre></td></tr> @@ -2319,15 +2320,16 @@ </pre></td></tr> -<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXOperatorCallExpr.html">CXXOperatorCallExpr</a>></td><td class="name" onclick="toggle('isAssignmentOperator1')"><a name="isAssignmentOperator1Anchor">isAssignmentOperator</a></td></tr> -<tr><td colspan="4" class="doc" id="isAssignmentOperator1"><pre>Matches all kinds of assignment operators. +<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXOperatorCallExpr.html">CXXOperatorCallExpr</a>></td><td class="name" onclick="toggle('isAssignmentOperator1')"><a name="isAssignmentOperator1Anchor">isAssignmentOperator</a></td><td></td></tr> +<tr><td colspan="4" class="doc" id="isAssignmentOperator1"><pre>Matches on all kinds of assignment operators. Example 1: matches a += b (matcher = binaryOperator(isAssignmentOperator())) if (a == b) a += b; -Example 2: matches s1 = s2 (matcher = cxxOperatorCallExpr(isAssignmentOperator())) - struct S { S& operator=(const S&); }; +Example 2: matches s1 = s2 + (matcher = cxxOperatorCallExpr(isAssignmentOperator())) + struct S { S& operator=(const S&); }; void x() { S s1, s2; s1 = s2; }) </pre></td></tr> @@ -2787,15 +2789,19 @@ <tr><td>Matcher<<a href="http://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. +<tr><td colspan="4" class="doc" id="isConstexpr1"><pre>Matches constexpr variable and function declarations, + and if constexpr. Given: constexpr int foo = 42; constexpr int bar(); + void baz() { if constexpr(1 > 0) {} } varDecl(isConstexpr()) matches the declaration of foo. functionDecl(isConstexpr()) matches the declaration of bar. +ifStmt(isConstexpr()) + matches the if statement in baz. </pre></td></tr> @@ -3037,6 +3043,23 @@ </pre></td></tr> +<tr><td>Matcher<<a href="http://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. + +Given: + constexpr int foo = 42; + constexpr int bar(); + void baz() { if constexpr(1 > 0) {} } +varDecl(isConstexpr()) + matches the declaration of foo. +functionDecl(isConstexpr()) + matches the declaration of bar. +ifStmt(isConstexpr()) + matches the if statement in baz. +</pre></td></tr> + + <tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1IntegerLiteral.html">IntegerLiteral</a>></td><td class="name" onclick="toggle('equals6')"><a name="equals6Anchor">equals</a></td><td>bool Value</td></tr> <tr><td colspan="4" class="doc" id="equals6"><pre></pre></td></tr> @@ -3801,15 +3824,19 @@ <tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>></td><td class="name" onclick="toggle('isConstexpr0')"><a name="isConstexpr0Anchor">isConstexpr</a></td><td></td></tr> -<tr><td colspan="4" class="doc" id="isConstexpr0"><pre>Matches constexpr variable and function declarations. +<tr><td colspan="4" class="doc" id="isConstexpr0"><pre>Matches constexpr variable and function declarations, + and if constexpr. Given: constexpr int foo = 42; constexpr int bar(); + void baz() { if constexpr(1 > 0) {} } varDecl(isConstexpr()) matches the declaration of foo. functionDecl(isConstexpr()) matches the declaration of bar. +ifStmt(isConstexpr()) + matches the if statement in baz. </pre></td></tr>
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits