From 856194d00c8ed012a2a5e9e6ae0c586f3304b021 Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Mon, 3 Dec 2012 15:43:25 +0000 Subject: [PATCH] Make hasDeclaration work for enums. llvm-svn: 169129 --- clang/include/clang/ASTMatchers/ASTMatchersInternal.h | 6 ++++-- clang/unittests/ASTMatchers/ASTMatchersTest.cpp | 6 ++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/clang/include/clang/ASTMatchers/ASTMatchersInternal.h b/clang/include/clang/ASTMatchers/ASTMatchersInternal.h index 0d25810e0a24..d77cccd82f62 100644 --- a/clang/include/clang/ASTMatchers/ASTMatchersInternal.h +++ b/clang/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(Node.getTypePtr())) + return matchesDecl(AsEnum->getDecl(), Finder, Builder); return matchesDecl(Node->getAsCXXRecordDecl(), Finder, Builder); } diff --git a/clang/unittests/ASTMatchers/ASTMatchersTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersTest.cpp index e94191400119..3ec685084507 100644 --- a/clang/unittests/ASTMatchers/ASTMatchersTest.cpp +++ b/clang/unittests/ASTMatchers/ASTMatchersTest.cpp @@ -779,6 +779,12 @@ TEST(Matcher, BindsIDForMemoizedResults) { new VerifyIdIsBoundTo("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( -- GitLab