From 08f0c53175bba899e7af6c6cc2cab25caf64ef2a Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Tue, 18 Sep 2012 14:17:42 +0000 Subject: [PATCH] Fix isDerivedFrom matcher. Without this patch, the isDerivedFrom matcher asserts in the "assert(ClassDecl != NULL);" in the new test, as a DependentTemplateSpecilizationType is not a sub-type of TemplateSpecializationType and also does not offer getAsCXXRecordDecl(). I am not sure why this did not cause problems before. It is now (after the changed implementation of isDerivedFrom) easier to write a matcher that actually gets into this branch of the code. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@164127 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/ASTMatchers/ASTMatchFinder.cpp | 1 + unittests/ASTMatchers/ASTMatchersTest.cpp | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/lib/ASTMatchers/ASTMatchFinder.cpp b/lib/ASTMatchers/ASTMatchFinder.cpp index cba2e50337..80ea16aa52 100644 --- a/lib/ASTMatchers/ASTMatchFinder.cpp +++ b/lib/ASTMatchers/ASTMatchFinder.cpp @@ -487,6 +487,7 @@ bool MatchASTVisitor::classIsDerivedFrom(const CXXRecordDecl *Declaration, // Type::getAs<...>() drills through typedefs. if (TypeNode->getAs() != NULL || + TypeNode->getAs() != NULL || TypeNode->getAs() != NULL) // Dependent names and template TypeNode parameters will be matched when // the template is instantiated. diff --git a/unittests/ASTMatchers/ASTMatchersTest.cpp b/unittests/ASTMatchers/ASTMatchersTest.cpp index b8ffaa4300..6556444bc2 100644 --- a/unittests/ASTMatchers/ASTMatchersTest.cpp +++ b/unittests/ASTMatchers/ASTMatchersTest.cpp @@ -294,6 +294,16 @@ TEST(DeclarationMatcher, ClassIsDerived) { recordDecl(isDerivedFrom(recordDecl(hasName("X")).bind("test"))))); } +TEST(DeclarationMatcher, ClassDerivedFromDependentTemplateSpecialization) { + EXPECT_TRUE(matches( + "template struct A {" + " template struct F {};" + "};" + "template struct B : A::template F {};" + "B b;", + recordDecl(hasName("B"), isDerivedFrom(recordDecl())))); +} + TEST(ClassTemplate, DoesNotMatchClass) { DeclarationMatcher ClassX = classTemplateDecl(hasName("X")); EXPECT_TRUE(notMatches("class X;", ClassX)); -- 2.40.0