summaryrefslogtreecommitdiff
path: root/unittests
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2012-11-16 18:39:22 +0000
committerDaniel Jasper <djasper@google.com>2012-11-16 18:39:22 +0000
commit5f684e90c2f44eda979573a01c2ed063d9adc7a8 (patch)
treed691a7d2693cd040b8a0021d0e1732083b134809 /unittests
parent58782bee56bf5e6ab42e6695af9ae5befe1fd479 (diff)
downloadclang-5f684e90c2f44eda979573a01c2ed063d9adc7a8.tar.gz
Fix partial-match-bind-behavior with forEachDescendant() matchers.
The problem is that a partial match of an (explicit or implicit) allOf matcher binds results, i.e. recordDecl(decl().bind("x"), hasName("A")) can very well bind a record that is not named "A". With this fix, the common cases of stumbling over this bug are fixed by the BoundNodesMap overwriting the results of a partial match. An error can still be created with a weird combination of anyOf and allOf (see inactive test). We need to decide whether this is worth fixing, as the fix will have performance impact. Review: http://llvm-reviews.chandlerc.com/D124 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@168177 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests')
-rw-r--r--unittests/ASTMatchers/ASTMatchersTest.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/unittests/ASTMatchers/ASTMatchersTest.cpp b/unittests/ASTMatchers/ASTMatchersTest.cpp
index 6d8c00058b..3eddccc652 100644
--- a/unittests/ASTMatchers/ASTMatchersTest.cpp
+++ b/unittests/ASTMatchers/ASTMatchersTest.cpp
@@ -2777,6 +2777,22 @@ TEST(ForEachDescendant, BindsOneNode) {
new VerifyIdIsBoundTo<FieldDecl>("x", 1)));
}
+TEST(ForEachDescendant, NestedForEachDescendant) {
+ DeclarationMatcher m = recordDecl(
+ isDefinition(), decl().bind("x"), hasName("C"));
+ EXPECT_TRUE(matchAndVerifyResultTrue(
+ "class A { class B { class C {}; }; };",
+ recordDecl(hasName("A"), anyOf(m, forEachDescendant(m))),
+ new VerifyIdIsBoundTo<Decl>("x", "C")));
+
+ // FIXME: This is not really a useful matcher, but the result is still
+ // surprising (currently binds "A").
+ //EXPECT_TRUE(matchAndVerifyResultTrue(
+ // "class A { class B { class C {}; }; };",
+ // recordDecl(hasName("A"), allOf(hasDescendant(m), anyOf(m, anything()))),
+ // new VerifyIdIsBoundTo<Decl>("x", "C")));
+}
+
TEST(ForEachDescendant, BindsMultipleNodes) {
EXPECT_TRUE(matchAndVerifyResultTrue(
"class C { class D { int x; int y; }; "