[cfe-commits] [PATCH] Fix isDerivedFrom matching on subclasses of dependent template specializations

Daniel Jasper reviews at llvm-reviews.chandlerc.com
Sun Sep 16 13:08:56 PDT 2012


Hi klimek, rsmith,

Without this patch, the isDerivedFrom matchers assert 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.

http://llvm-reviews.chandlerc.com/D42

Files:
  lib/ASTMatchers/ASTMatchFinder.cpp
  unittests/ASTMatchers/ASTMatchersTest.cpp

Index: lib/ASTMatchers/ASTMatchFinder.cpp
===================================================================
--- lib/ASTMatchers/ASTMatchFinder.cpp
+++ lib/ASTMatchers/ASTMatchFinder.cpp
@@ -487,6 +487,7 @@
 
     // Type::getAs<...>() drills through typedefs.
     if (TypeNode->getAs<DependentNameType>() != NULL ||
+        TypeNode->getAs<DependentTemplateSpecializationType>() != NULL ||
         TypeNode->getAs<TemplateTypeParmType>() != NULL)
       // Dependent names and template TypeNode parameters will be matched when
       // the template is instantiated.
Index: unittests/ASTMatchers/ASTMatchersTest.cpp
===================================================================
--- unittests/ASTMatchers/ASTMatchersTest.cpp
+++ unittests/ASTMatchers/ASTMatchersTest.cpp
@@ -294,6 +294,16 @@
       recordDecl(isDerivedFrom(recordDecl(hasName("X")).bind("test")))));
 }
 
+TEST(DeclarationMatcher, ClassDerivedFromDependentTemplateSpecialization) {
+  EXPECT_TRUE(matches(
+     "template <typename T> struct A {"
+     "  template <typename T2> struct F {};"
+     "};"
+     "template <typename T> struct B : A<T>::template F<T> {};"
+     "B<int> b;",
+     recordDecl(hasName("B"), isDerivedFrom(recordDecl()))));
+}
+
 TEST(ClassTemplate, DoesNotMatchClass) {
   DeclarationMatcher ClassX = classTemplateDecl(hasName("X"));
   EXPECT_TRUE(notMatches("class X;", ClassX));
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D42.1.patch
Type: text/x-patch
Size: 1387 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20120916/8af250e8/attachment.bin>


More information about the cfe-commits mailing list