diff options
author | Malcolm Parsons <malcolm.parsons@gmail.com> | 2017-08-01 09:53:55 +0000 |
---|---|---|
committer | Malcolm Parsons <malcolm.parsons@gmail.com> | 2017-08-01 09:53:55 +0000 |
commit | 31d08b6e51f25e97cc9de9e8f1c26773c33eee1c (patch) | |
tree | fcd75a1de1ae56ce23bfbe334aed278ff9cd92da | |
parent | d56595184b5c5edc138c6ae677a1ac38a9a31581 (diff) | |
download | bcm5719-llvm-31d08b6e51f25e97cc9de9e8f1c26773c33eee1c.tar.gz bcm5719-llvm-31d08b6e51f25e97cc9de9e8f1c26773c33eee1c.zip |
[ASTMatchers] Allow forField to match indirect fields.
This is needed for PR32966.
Reviewed by alexfh.
llvm-svn: 309667
-rw-r--r-- | clang/include/clang/ASTMatchers/ASTMatchers.h | 2 | ||||
-rw-r--r-- | clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp | 8 |
2 files changed, 7 insertions, 3 deletions
diff --git a/clang/include/clang/ASTMatchers/ASTMatchers.h b/clang/include/clang/ASTMatchers/ASTMatchers.h index c9b496df33f..a4fc6faa663 100644 --- a/clang/include/clang/ASTMatchers/ASTMatchers.h +++ b/clang/include/clang/ASTMatchers/ASTMatchers.h @@ -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)); } diff --git a/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp index 5957c7fa41d..3e268435ef7 100644 --- a/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp +++ b/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp @@ -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")))))))); } |