<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>
</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>
<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>
return FnTy->isNothrow();
}
-/// \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();
}
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) {