diff options
-rw-r--r-- | clang/include/clang/ASTMatchers/ASTMatchers.h | 4 | ||||
-rw-r--r-- | clang/unittests/ASTMatchers/ASTMatchersTest.cpp | 6 |
2 files changed, 8 insertions, 2 deletions
diff --git a/clang/include/clang/ASTMatchers/ASTMatchers.h b/clang/include/clang/ASTMatchers/ASTMatchers.h index 3015b0841f2..6507433e332 100644 --- a/clang/include/clang/ASTMatchers/ASTMatchers.h +++ b/clang/include/clang/ASTMatchers/ASTMatchers.h @@ -342,8 +342,8 @@ AST_MATCHER_P(TemplateArgument, refersToType, /// \c B::next AST_MATCHER_P(TemplateArgument, refersToDeclaration, internal::Matcher<Decl>, 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/clang/unittests/ASTMatchers/ASTMatchersTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersTest.cpp index 69e61f296ff..b49d082501b 100644 --- a/clang/unittests/ASTMatchers/ASTMatchersTest.cpp +++ b/clang/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 <typename T> struct A {};" + "A<int> a;", + classTemplateSpecializationDecl(hasAnyTemplateArgument( + refersToDeclaration(decl()))))); } TEST(Matcher, MatchesSpecificArgument) { |