]> granicus.if.org Git - clang/commitdiff
Add isListInitialization matcher.
authorPeter Collingbourne <peter@pcc.me.uk>
Thu, 6 Feb 2014 21:52:24 +0000 (21:52 +0000)
committerPeter Collingbourne <peter@pcc.me.uk>
Thu, 6 Feb 2014 21:52:24 +0000 (21:52 +0000)
Differential Revision: http://llvm-reviews.chandlerc.com/D2708

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@200949 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/ASTMatchers/ASTMatchers.h
lib/ASTMatchers/Dynamic/Registry.cpp
unittests/ASTMatchers/ASTMatchersTest.cpp

index 4be693f29292a7aac067be51c21a79b243643201..5355a9a857866fba57df59c151cb0d33e6c46a48 100644 (file)
@@ -2186,6 +2186,11 @@ AST_POLYMORPHIC_MATCHER_P(hasAnyArgument, AST_POLYMORPHIC_SUPPORTED_TYPES_2(
   return false;
 }
 
+/// \brief Matches a constructor call expression which uses list initialization.
+AST_MATCHER(CXXConstructExpr, isListInitialization) {
+  return Node.isListInitialization();
+}
+
 /// \brief Matches the n'th parameter of a function declaration.
 ///
 /// Given
index 1c7215e327367598b6cc90117e1bb6374c8fb469..11230ad049dfeb97000d4d0e8dbb921732d857a9 100644 (file)
@@ -231,6 +231,7 @@ RegistryMaps::RegistryMaps() {
   REGISTER_MATCHER(isExternC);
   REGISTER_MATCHER(isImplicit);
   REGISTER_MATCHER(isInteger);
+  REGISTER_MATCHER(isListInitialization);
   REGISTER_MATCHER(isOverride);
   REGISTER_MATCHER(isPrivate);
   REGISTER_MATCHER(isProtected);
index 8825174c4999f9766c701760ce37ae0e2994157d..5c9753f9336b869ff4c6fb5d83a1b71ec2153f62 100644 (file)
@@ -1637,6 +1637,17 @@ TEST(Matcher, ConstructorArgumentCount) {
                  Constructor1Arg));
 }
 
+TEST(Matcher, ConstructorListInitialization) {
+  StatementMatcher ConstructorListInit = constructExpr(isListInitialization());
+
+  EXPECT_TRUE(
+      matches("class X { public: X(int); }; void x() { X x{0}; }",
+              ConstructorListInit));
+  EXPECT_FALSE(
+      matches("class X { public: X(int); }; void x() { X x(0); }",
+              ConstructorListInit));
+}
+
 TEST(Matcher,ThisExpr) {
   EXPECT_TRUE(
       matches("struct X { int a; int f () { return a; } };", thisExpr()));