Index: docs/LibASTMatchersReference.html =================================================================== --- docs/LibASTMatchersReference.html +++ docs/LibASTMatchersReference.html @@ -1926,15 +1926,16 @@ -
Matches all kinds of assignment operators. ++ Matcher<BinaryOperator> isAssignmentOperator @@ -2319,15 +2320,16 @@ 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; })
Matches all kinds of assignment operators. ++ Matcher<CXXOperatorCallExpr> isAssignmentOperator @@ -2787,15 +2789,19 @@ 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; })- Matcher<FunctionDecl> isConstexpr + Matches constexpr variable and function declarations. +@@ -3037,6 +3043,23 @@ 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.+ Matcher<IfStmt> isConstexpr + + 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. +Matcher<IntegerLiteral> equals bool Value @@ -3801,15 +3824,19 @@ - Matcher<VarDecl> isConstexpr Matches constexpr variable and function declarations. +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: 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) { 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.