From aaa8e45b8e392a1f1b7498e2f00c6ed66d41119a Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Sat, 29 Sep 2012 15:55:18 +0000 Subject: [PATCH] Fix refersToDeclaration()-matcher and add missing test case. This was broken as of r164656 as TemplateArgument::getAsDecl() now asserts instead of returning NULL for other template arugment kinds. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@164896 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/ASTMatchers/ASTMatchers.h | 4 ++-- unittests/ASTMatchers/ASTMatchersTest.cpp | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/include/clang/ASTMatchers/ASTMatchers.h b/include/clang/ASTMatchers/ASTMatchers.h index 3015b0841f..6507433e33 100644 --- a/include/clang/ASTMatchers/ASTMatchers.h +++ b/include/clang/ASTMatchers/ASTMatchers.h @@ -342,8 +342,8 @@ AST_MATCHER_P(TemplateArgument, refersToType, /// \c B::next AST_MATCHER_P(TemplateArgument, refersToDeclaration, internal::Matcher, InnerMatcher) { - if (const Decl *Declaration = Node.getAsDecl()) - return InnerMatcher.matches(*Declaration, Finder, Builder); + if (Node.getKind() == TemplateArgument::Declaration) + return InnerMatcher.matches(*Node.getAsDecl(), Finder, Builder); return false; } diff --git a/unittests/ASTMatchers/ASTMatchersTest.cpp b/unittests/ASTMatchers/ASTMatchersTest.cpp index 69e61f296f..b49d082501 100644 --- a/unittests/ASTMatchers/ASTMatchersTest.cpp +++ b/unittests/ASTMatchers/ASTMatchersTest.cpp @@ -1236,6 +1236,12 @@ TEST(Matcher, MatchesDeclarationReferenceTemplateArgument) { "A<&B::next> a;", classTemplateSpecializationDecl(hasAnyTemplateArgument( refersToDeclaration(fieldDecl(hasName("next"))))))); + + EXPECT_TRUE(notMatches( + "template struct A {};" + "A a;", + classTemplateSpecializationDecl(hasAnyTemplateArgument( + refersToDeclaration(decl()))))); } TEST(Matcher, MatchesSpecificArgument) { -- 2.40.0