diff options
| author | Daniel Jasper <djasper@google.com> | 2012-09-18 14:17:42 +0000 |
|---|---|---|
| committer | Daniel Jasper <djasper@google.com> | 2012-09-18 14:17:42 +0000 |
| commit | 83dafaf3db495f2a8e865055557d2179a58cf21e (patch) | |
| tree | ad2391b32c6d6db390a836f2bd9d6152222afaae | |
| parent | be88f563bf6c7640ab1f74472d730e0fe71061b2 (diff) | |
| download | bcm5719-llvm-83dafaf3db495f2a8e865055557d2179a58cf21e.tar.gz bcm5719-llvm-83dafaf3db495f2a8e865055557d2179a58cf21e.zip | |
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.
llvm-svn: 164127
| -rw-r--r-- | clang/lib/ASTMatchers/ASTMatchFinder.cpp | 1 | ||||
| -rw-r--r-- | clang/unittests/ASTMatchers/ASTMatchersTest.cpp | 10 |
2 files changed, 11 insertions, 0 deletions
diff --git a/clang/lib/ASTMatchers/ASTMatchFinder.cpp b/clang/lib/ASTMatchers/ASTMatchFinder.cpp index cba2e503379..80ea16aa525 100644 --- a/clang/lib/ASTMatchers/ASTMatchFinder.cpp +++ b/clang/lib/ASTMatchers/ASTMatchFinder.cpp @@ -487,6 +487,7 @@ bool MatchASTVisitor::classIsDerivedFrom(const CXXRecordDecl *Declaration, // 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. diff --git a/clang/unittests/ASTMatchers/ASTMatchersTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersTest.cpp index b8ffaa43001..6556444bc24 100644 --- a/clang/unittests/ASTMatchers/ASTMatchersTest.cpp +++ b/clang/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 <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)); |

