Make hasDeclaration work for enums.

llvm-svn: 169129
This commit is contained in:
Daniel Jasper 2012-12-03 15:43:25 +00:00
parent 485f7b4a70
commit 856194d00c
2 changed files with 10 additions and 2 deletions

View 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);
}

View 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(