diff options
Diffstat (limited to 'clang/unittests/ASTMatchers/ASTMatchersTest.cpp')
-rw-r--r-- | clang/unittests/ASTMatchers/ASTMatchersTest.cpp | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/clang/unittests/ASTMatchers/ASTMatchersTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersTest.cpp index 9d9b2a15b79..691719c04e4 100644 --- a/clang/unittests/ASTMatchers/ASTMatchersTest.cpp +++ b/clang/unittests/ASTMatchers/ASTMatchersTest.cpp @@ -4158,24 +4158,32 @@ public: } 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 { |