summaryrefslogtreecommitdiffstats
path: root/clang/unittests/ASTMatchers/ASTMatchersTest.cpp
diff options
context:
space:
mode:
authorManuel Klimek <klimek@google.com>2014-03-25 14:39:26 +0000
committerManuel Klimek <klimek@google.com>2014-03-25 14:39:26 +0000
commitce68f7714aed51c77d3ff36a9c0252327824386e (patch)
tree585b7aa5d257b9e57fd66d76b60e6826d35a19ed /clang/unittests/ASTMatchers/ASTMatchersTest.cpp
parent86f318e8b4313d6fee4f53c3a0d86c61dd8678c9 (diff)
downloadbcm5719-llvm-ce68f7714aed51c77d3ff36a9c0252327824386e.tar.gz
bcm5719-llvm-ce68f7714aed51c77d3ff36a9c0252327824386e.zip
Fixes a bug in DynTypedNode.
Two DynTypedNodes can be equal if they do not have the same node type, because DynTypedNodes for the same underlying object might have been created from different types (for example, Decl vs VarDecl). llvm-svn: 204722
Diffstat (limited to 'clang/unittests/ASTMatchers/ASTMatchersTest.cpp')
-rw-r--r--clang/unittests/ASTMatchers/ASTMatchersTest.cpp33
1 files changed, 32 insertions, 1 deletions
diff --git a/clang/unittests/ASTMatchers/ASTMatchersTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersTest.cpp
index f1b792139d9..787f81992d9 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersTest.cpp
@@ -4260,7 +4260,6 @@ TEST(EqualsBoundNodeMatcher, Type) {
}
TEST(EqualsBoundNodeMatcher, UsingForEachDescendant) {
-
EXPECT_TRUE(matchAndVerifyResultTrue(
"int f() {"
" if (1) {"
@@ -4294,5 +4293,37 @@ TEST(EqualsBoundNodeMatcher, FiltersMatchedCombinations) {
new VerifyIdIsBoundTo<VarDecl>("d", 5)));
}
+TEST(EqualsBoundNodeMatcher, UnlessDescendantsOfAncestorsMatch) {
+ EXPECT_TRUE(matchAndVerifyResultTrue(
+ "struct StringRef { int size() const; const char* data() const; };"
+ "void f(StringRef v) {"
+ " v.data();"
+ "}",
+ memberCallExpr(
+ callee(methodDecl(hasName("data"))),
+ on(declRefExpr(to(varDecl(hasType(recordDecl(hasName("StringRef"))))
+ .bind("var")))),
+ unless(hasAncestor(stmt(hasDescendant(memberCallExpr(
+ callee(methodDecl(anyOf(hasName("size"), hasName("length")))),
+ on(declRefExpr(to(varDecl(equalsBoundNode("var")))))))))))
+ .bind("data"),
+ new VerifyIdIsBoundTo<Expr>("data", 1)));
+
+ EXPECT_FALSE(matches(
+ "struct StringRef { int size() const; const char* data() const; };"
+ "void f(StringRef v) {"
+ " v.data();"
+ " v.size();"
+ "}",
+ memberCallExpr(
+ callee(methodDecl(hasName("data"))),
+ on(declRefExpr(to(varDecl(hasType(recordDecl(hasName("StringRef"))))
+ .bind("var")))),
+ unless(hasAncestor(stmt(hasDescendant(memberCallExpr(
+ callee(methodDecl(anyOf(hasName("size"), hasName("length")))),
+ on(declRefExpr(to(varDecl(equalsBoundNode("var")))))))))))
+ .bind("data")));
+}
+
} // end namespace ast_matchers
} // end namespace clang
OpenPOWER on IntegriCloud