]> granicus.if.org Git - clang/commitdiff
Make hasDeclaration work for enums.
authorDaniel Jasper <djasper@google.com>
Mon, 3 Dec 2012 15:43:25 +0000 (15:43 +0000)
committerDaniel Jasper <djasper@google.com>
Mon, 3 Dec 2012 15:43:25 +0000 (15:43 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@169129 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/ASTMatchers/ASTMatchersInternal.h
unittests/ASTMatchers/ASTMatchersTest.cpp

index 0d25810e0a24c624225844043c9a2a369d4be22c..d77cccd82f6270c0d7da53af5fbacc85ea56fa51 100644 (file)
@@ -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);
   }
 
index e94191400119f3dd84a55bae5a7109bfce133eb7..3ec685084507a5f030b202e3fc6ad82db41796a6 100644 (file)
@@ -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(