forked from OSchip/llvm-project
Adding new AST matcher: isConstexpr
It matches constexpr variable and function declarations. llvm-svn: 238016
This commit is contained in:
parent
575f7d4f1c
commit
b37b0ed239
|
|
@ -2709,6 +2709,23 @@ AST_MATCHER(FunctionDecl, isDeleted) {
|
||||||
return Node.isDeleted();
|
return Node.isDeleted();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// \brief Matches constexpr variable and function declarations.
|
||||||
|
///
|
||||||
|
/// Given:
|
||||||
|
/// \code
|
||||||
|
/// constexpr int foo = 42;
|
||||||
|
/// constexpr int bar();
|
||||||
|
/// \endcode
|
||||||
|
/// varDecl(isConstexpr())
|
||||||
|
/// matches the declaration of foo.
|
||||||
|
/// functionDecl(isConstexpr())
|
||||||
|
/// matches the declaration of bar.
|
||||||
|
AST_POLYMORPHIC_MATCHER(isConstexpr,
|
||||||
|
AST_POLYMORPHIC_SUPPORTED_TYPES(VarDecl,
|
||||||
|
FunctionDecl)) {
|
||||||
|
return Node.isConstexpr();
|
||||||
|
}
|
||||||
|
|
||||||
/// \brief Matches the condition expression of an if statement, for loop,
|
/// \brief Matches the condition expression of an if statement, for loop,
|
||||||
/// or conditional operator.
|
/// or conditional operator.
|
||||||
///
|
///
|
||||||
|
|
|
||||||
|
|
@ -1595,6 +1595,13 @@ TEST(IsDeleted, MatchesDeletedFunctionDeclarations) {
|
||||||
functionDecl(hasName("Func"), isDeleted())));
|
functionDecl(hasName("Func"), isDeleted())));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(isConstexpr, MatchesConstexprDeclarations) {
|
||||||
|
EXPECT_TRUE(matches("constexpr int foo = 42;",
|
||||||
|
varDecl(hasName("foo"), isConstexpr())));
|
||||||
|
EXPECT_TRUE(matches("constexpr int bar();",
|
||||||
|
functionDecl(hasName("bar"), isConstexpr())));
|
||||||
|
}
|
||||||
|
|
||||||
TEST(HasAnyParameter, DoesntMatchIfInnerMatcherDoesntMatch) {
|
TEST(HasAnyParameter, DoesntMatchIfInnerMatcherDoesntMatch) {
|
||||||
EXPECT_TRUE(notMatches("class Y {}; class X { void x(int) {} };",
|
EXPECT_TRUE(notMatches("class Y {}; class X { void x(int) {} };",
|
||||||
methodDecl(hasAnyParameter(hasType(recordDecl(hasName("X")))))));
|
methodDecl(hasAnyParameter(hasType(recordDecl(hasName("X")))))));
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue