From b37b0ed239f51932b3c58d03f12b7f213a99cf1b Mon Sep 17 00:00:00 2001 From: Szabolcs Sipos Date: Fri, 22 May 2015 11:35:50 +0000 Subject: [PATCH] Adding new AST matcher: isConstexpr It matches constexpr variable and function declarations. llvm-svn: 238016 --- clang/include/clang/ASTMatchers/ASTMatchers.h | 17 +++++++++++++++++ clang/unittests/ASTMatchers/ASTMatchersTest.cpp | 7 +++++++ 2 files changed, 24 insertions(+) diff --git a/clang/include/clang/ASTMatchers/ASTMatchers.h b/clang/include/clang/ASTMatchers/ASTMatchers.h index 94906d190bff..7f9764619c2b 100644 --- a/clang/include/clang/ASTMatchers/ASTMatchers.h +++ b/clang/include/clang/ASTMatchers/ASTMatchers.h @@ -2709,6 +2709,23 @@ AST_MATCHER(FunctionDecl, 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, /// or conditional operator. /// diff --git a/clang/unittests/ASTMatchers/ASTMatchersTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersTest.cpp index 6f1cf3fe2c82..ae363e974b5d 100644 --- a/clang/unittests/ASTMatchers/ASTMatchersTest.cpp +++ b/clang/unittests/ASTMatchers/ASTMatchersTest.cpp @@ -1595,6 +1595,13 @@ TEST(IsDeleted, MatchesDeletedFunctionDeclarations) { 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) { EXPECT_TRUE(notMatches("class Y {}; class X { void x(int) {} };", methodDecl(hasAnyParameter(hasType(recordDecl(hasName("X")))))));