diff options
author | Manuel Klimek <klimek@google.com> | 2014-05-27 12:31:10 +0000 |
---|---|---|
committer | Manuel Klimek <klimek@google.com> | 2014-05-27 12:31:10 +0000 |
commit | e0652d113ae77cb181c7164569e34af1f53612da (patch) | |
tree | e5879c989ed9ac8fdc0eb47809278ae10f43b264 /unittests/ASTMatchers | |
parent | 80678be7b0a70843ac2cd2dae0efbe274df0782e (diff) | |
download | clang-e0652d113ae77cb181c7164569e34af1f53612da.tar.gz clang-e0652d113ae77cb181c7164569e34af1f53612da.tar.bz2 clang-e0652d113ae77cb181c7164569e34af1f53612da.tar.xz |
Make equalsNode work with pointers to subtypes.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@209652 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/ASTMatchers')
-rw-r--r-- | unittests/ASTMatchers/ASTMatchersTest.cpp | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/unittests/ASTMatchers/ASTMatchersTest.cpp b/unittests/ASTMatchers/ASTMatchersTest.cpp index 9d9b2a15b7..691719c04e 100644 --- a/unittests/ASTMatchers/ASTMatchersTest.cpp +++ b/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 { |