Index: docs/LibASTMatchersReference.html =================================================================== --- docs/LibASTMatchersReference.html +++ docs/LibASTMatchersReference.html @@ -176,7 +176,7 @@ -Matcher<Decl>cxxMethodDeclMatcher<CXXMethodDecl>... +Matcher<Decl>cxxMethodDeclMatcher<CXXMethodDecl>...
Matches method declarations.
 
 Example matches y
@@ -650,7 +650,7 @@
 
-Matcher<Stmt>binaryConditionalOperatorMatcher<BinaryConditionalOperator>... +Matcher<Stmt>binaryConditionalOperatorMatcher<BinaryConditionalOperator>...
Matches binary conditional operator expressions (GNU extension).
 
 Example matches a ?: b
@@ -975,7 +975,7 @@
 
-Matcher<Stmt>cxxThrowExprMatcher<CXXThrowExpr>... +Matcher<Stmt>cxxThrowExprMatcher<CXXThrowExpr>...
Matches throw expressions.
 
   try { throw 5; } catch(int i) {}
@@ -1926,15 +1926,16 @@
 
-Matcher<BinaryOperator>isAssignmentOperator -
Matches all kinds of assignment operators.
+Matcher<BinaryOperator>isAssignmentOperator
+
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; })
 
@@ -2159,7 +2160,7 @@
-Matcher<CXXMethodDecl>isConst +Matcher<CXXMethodDecl>isConst
Matches if the given method declaration is const.
 
 Given
@@ -2172,7 +2173,7 @@
 
-Matcher<CXXMethodDecl>isCopyAssignmentOperator +Matcher<CXXMethodDecl>isCopyAssignmentOperator
Matches if the given method declaration declares a copy assignment
 operator.
 
@@ -2187,7 +2188,7 @@
 
-Matcher<CXXMethodDecl>isFinal +Matcher<CXXMethodDecl>isFinal
Matches if the given method or class declaration is final.
 
 Given:
@@ -2204,7 +2205,7 @@
 
-Matcher<CXXMethodDecl>isMoveAssignmentOperator +Matcher<CXXMethodDecl>isMoveAssignmentOperator
Matches if the given method declaration declares a move assignment
 operator.
 
@@ -2219,7 +2220,7 @@
 
-Matcher<CXXMethodDecl>isOverride +Matcher<CXXMethodDecl>isOverride
Matches if the given method declaration overrides another method.
 
 Given
@@ -2235,7 +2236,7 @@
 
-Matcher<CXXMethodDecl>isPure +Matcher<CXXMethodDecl>isPure
Matches if the given method declaration is pure.
 
 Given
@@ -2247,7 +2248,7 @@
 
-Matcher<CXXMethodDecl>isUserProvided +Matcher<CXXMethodDecl>isUserProvided
Matches method declarations that are user-provided.
 
 Given
@@ -2260,7 +2261,7 @@
 
-Matcher<CXXMethodDecl>isVirtual +Matcher<CXXMethodDecl>isVirtual
Matches if the given method declaration is virtual.
 
 Given
@@ -2272,7 +2273,7 @@
 
-Matcher<CXXMethodDecl>isVirtualAsWritten +Matcher<CXXMethodDecl>isVirtualAsWritten
Matches if the given method declaration has an explicit "virtual".
 
 Given
@@ -2319,15 +2320,16 @@
 
-Matcher<CXXOperatorCallExpr>isAssignmentOperator -
Matches all kinds of assignment operators.
+Matcher<CXXOperatorCallExpr>isAssignmentOperator
+
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; })
 
@@ -2787,15 +2789,19 @@ Matcher<FunctionDecl>isConstexpr -
Matches constexpr variable and function declarations.
+
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.
 
@@ -3037,6 +3043,23 @@
+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>equalsbool Value

 
@@ -3801,15 +3824,19 @@
 
 
 Matcher<VarDecl>isConstexpr
-
Matches constexpr variable and function declarations.
+
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.
 
@@ -4556,7 +4583,7 @@
-Matcher<CXXMethodDecl>forEachOverriddenMatcher<CXXMethodDecl> InnerMatcher +Matcher<CXXMethodDecl>forEachOverriddenMatcher<CXXMethodDecl> InnerMatcher
Matches each method overridden by the given method. This matcher may
 produce multiple matches.
 
@@ -4580,7 +4607,7 @@
 
-Matcher<CXXMethodDecl>ofClassMatcher<CXXRecordDecl> InnerMatcher +Matcher<CXXMethodDecl>ofClassMatcher<CXXRecordDecl> InnerMatcher
Matches the class declaration that the given method declaration
 belongs to.
 
@@ -4642,7 +4669,7 @@
 
-Matcher<CXXRecordDecl>hasMethodMatcher<CXXMethodDecl> InnerMatcher +Matcher<CXXRecordDecl>hasMethodMatcher<CXXMethodDecl> InnerMatcher
Matches the first method of a class or struct that satisfies InnerMatcher.
 
 Given:
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) {