[PATCH] New AST matcher: isConstexpr()

Szabolcs Sipos szabolcs.sipos at ericsson.com
Fri May 22 02:56:35 PDT 2015


From now on isConstexpr() matches constexpr VarDecls as well.


http://reviews.llvm.org/D9917

Files:
  include/clang/ASTMatchers/ASTMatchers.h
  unittests/ASTMatchers/ASTMatchersTest.cpp

Index: include/clang/ASTMatchers/ASTMatchers.h
===================================================================
--- include/clang/ASTMatchers/ASTMatchers.h
+++ include/clang/ASTMatchers/ASTMatchers.h
@@ -2709,6 +2709,23 @@
   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.
 ///
Index: unittests/ASTMatchers/ASTMatchersTest.cpp
===================================================================
--- unittests/ASTMatchers/ASTMatchersTest.cpp
+++ unittests/ASTMatchers/ASTMatchersTest.cpp
@@ -1595,6 +1595,13 @@
                       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")))))));

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D9917.26313.patch
Type: text/x-patch
Size: 1687 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150522/4eea2221/attachment.bin>


More information about the cfe-commits mailing list