Add isListInitialization matcher.

Differential Revision: http://llvm-reviews.chandlerc.com/D2708

llvm-svn: 200949
This commit is contained in:
Peter Collingbourne 2014-02-06 21:52:24 +00:00
parent 3d584b0ced
commit 1fec3dfe43
3 changed files with 17 additions and 0 deletions

View 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

View 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);

View 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()));