Make equalsNode work with pointers to subtypes.
llvm-svn: 209652
diff --git a/clang/unittests/ASTMatchers/ASTMatchersTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersTest.cpp
index 9d9b2a1..691719c 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersTest.cpp
@@ -4158,24 +4158,32 @@
}
bool verify(const BoundNodes &Nodes, ASTContext &Context, const Stmt *Node) {
+ // Use the original typed pointer to verify we can pass pointers to subtypes
+ // to equalsNode.
+ const T *TypedNode = cast<T>(Node);
return selectFirst<const T>(
- "", match(stmt(hasParent(stmt(has(stmt(equalsNode(Node)))).bind(""))),
- *Node, Context)) != NULL;
+ "", match(stmt(hasParent(
+ stmt(has(stmt(equalsNode(TypedNode)))).bind(""))),
+ *Node, Context)) != NULL;
}
bool verify(const BoundNodes &Nodes, ASTContext &Context, const Decl *Node) {
+ // Use the original typed pointer to verify we can pass pointers to subtypes
+ // to equalsNode.
+ const T *TypedNode = cast<T>(Node);
return selectFirst<const T>(
- "", match(decl(hasParent(decl(has(decl(equalsNode(Node)))).bind(""))),
- *Node, Context)) != NULL;
+ "", match(decl(hasParent(
+ decl(has(decl(equalsNode(TypedNode)))).bind(""))),
+ *Node, Context)) != NULL;
}
};
TEST(IsEqualTo, MatchesNodesByIdentity) {
EXPECT_TRUE(matchAndVerifyResultTrue(
"class X { class Y {}; };", recordDecl(hasName("::X::Y")).bind(""),
- new VerifyAncestorHasChildIsEqual<Decl>()));
- EXPECT_TRUE(
- matchAndVerifyResultTrue("void f() { if(true) {} }", ifStmt().bind(""),
- new VerifyAncestorHasChildIsEqual<Stmt>()));
+ new VerifyAncestorHasChildIsEqual<CXXRecordDecl>()));
+ EXPECT_TRUE(matchAndVerifyResultTrue(
+ "void f() { if (true) if(true) {} }", ifStmt().bind(""),
+ new VerifyAncestorHasChildIsEqual<IfStmt>()));
}
class VerifyStartOfTranslationUnit : public MatchFinder::MatchCallback {