[ASTMatchers] Allow forField to match indirect fields.

This is needed for PR32966.

Reviewed by alexfh.

llvm-svn: 309667
This commit is contained in:
Malcolm Parsons 2017-08-01 09:53:55 +00:00
parent d56595184b
commit 31d08b6e51
2 changed files with 7 additions and 3 deletions

View File

@ -3237,7 +3237,7 @@ AST_MATCHER_P(CXXConstructorDecl, hasAnyConstructorInitializer,
/// with forField matching foo_
AST_MATCHER_P(CXXCtorInitializer, forField,
internal::Matcher<FieldDecl>, InnerMatcher) {
const FieldDecl *NodeAsDecl = Node.getMember();
const FieldDecl *NodeAsDecl = Node.getAnyMember();
return (NodeAsDecl != nullptr &&
InnerMatcher.matches(*NodeAsDecl, Finder, Builder));
}

View File

@ -785,14 +785,18 @@ TEST(HasAnyConstructorInitializer, ForField) {
static const char Code[] =
"class Baz { };"
"class Foo {"
" Foo() : foo_() { }"
" Foo() : foo_(), bar_() { }"
" Baz foo_;"
" Baz bar_;"
" struct {"
" Baz bar_;"
" };"
"};";
EXPECT_TRUE(matches(Code, cxxConstructorDecl(hasAnyConstructorInitializer(
forField(hasType(recordDecl(hasName("Baz"))))))));
EXPECT_TRUE(matches(Code, cxxConstructorDecl(hasAnyConstructorInitializer(
forField(hasName("foo_"))))));
EXPECT_TRUE(matches(Code, cxxConstructorDecl(hasAnyConstructorInitializer(
forField(hasName("bar_"))))));
EXPECT_TRUE(notMatches(Code, cxxConstructorDecl(hasAnyConstructorInitializer(
forField(hasType(recordDecl(hasName("Bar"))))))));
}