diff options
author | Daniel Jasper <djasper@google.com> | 2012-12-03 15:43:25 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2012-12-03 15:43:25 +0000 |
commit | 189f2e421d06526ea8b4a3dcd9f4a072e10a859c (patch) | |
tree | 848f8da02577f4737708d25e33aaca707fc18466 | |
parent | 09ccf39c13cfca102deea2986f45cb908bc232fd (diff) |
Make hasDeclaration work for enums.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@169129 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/ASTMatchers/ASTMatchersInternal.h | 6 | ||||
-rw-r--r-- | unittests/ASTMatchers/ASTMatchersTest.cpp | 6 |
2 files changed, 10 insertions, 2 deletions
diff --git a/include/clang/ASTMatchers/ASTMatchersInternal.h b/include/clang/ASTMatchers/ASTMatchersInternal.h index 0d25810e0a..d77cccd82f 100644 --- a/include/clang/ASTMatchers/ASTMatchersInternal.h +++ b/include/clang/ASTMatchers/ASTMatchersInternal.h @@ -373,13 +373,15 @@ public: } private: - /// \brief Extracts the CXXRecordDecl of a QualType and returns whether the - /// inner matcher matches on it. + /// \brief Extracts the CXXRecordDecl or EnumDecl of a QualType and returns + /// whether the inner matcher matches on it. bool matchesSpecialized(const QualType &Node, ASTMatchFinder *Finder, BoundNodesTreeBuilder *Builder) const { /// FIXME: Add other ways to convert... if (Node.isNull()) return false; + if (const EnumType *AsEnum = dyn_cast<EnumType>(Node.getTypePtr())) + return matchesDecl(AsEnum->getDecl(), Finder, Builder); return matchesDecl(Node->getAsCXXRecordDecl(), Finder, Builder); } diff --git a/unittests/ASTMatchers/ASTMatchersTest.cpp b/unittests/ASTMatchers/ASTMatchersTest.cpp index e941914001..3ec6850845 100644 --- a/unittests/ASTMatchers/ASTMatchersTest.cpp +++ b/unittests/ASTMatchers/ASTMatchersTest.cpp @@ -779,6 +779,12 @@ TEST(Matcher, BindsIDForMemoizedResults) { new VerifyIdIsBoundTo<Decl>("x", 2))); } +TEST(HasDeclaration, HasDeclarationOfEnumType) { + EXPECT_TRUE(matches("enum X {}; void y(X *x) { x; }", + expr(hasType(pointsTo( + qualType(hasDeclaration(enumDecl(hasName("X"))))))))); +} + TEST(HasType, TakesQualTypeMatcherAndMatchesExpr) { TypeMatcher ClassX = hasDeclaration(recordDecl(hasName("X"))); EXPECT_TRUE( |