[cfe-commits] r169262 - in /cfe/trunk: lib/ASTMatchers/ASTMatchFinder.cpp unittests/ASTMatchers/ASTMatchersTest.cpp
Manuel Klimek
klimek at google.com
Tue Dec 4 05:40:29 PST 2012
Author: klimek
Date: Tue Dec 4 07:40:29 2012
New Revision: 169262
URL: http://llvm.org/viewvc/llvm-project?rev=169262&view=rev
Log:
Fixes crash in isDerivedFrom for recursive templates.
Modified:
cfe/trunk/lib/ASTMatchers/ASTMatchFinder.cpp
cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp
Modified: cfe/trunk/lib/ASTMatchers/ASTMatchFinder.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ASTMatchers/ASTMatchFinder.cpp?rev=169262&r1=169261&r2=169262&view=diff
==============================================================================
--- cfe/trunk/lib/ASTMatchers/ASTMatchFinder.cpp (original)
+++ cfe/trunk/lib/ASTMatchers/ASTMatchFinder.cpp Tue Dec 4 07:40:29 2012
@@ -605,7 +605,12 @@
ClassDecl = TypeNode->getAsCXXRecordDecl();
}
assert(ClassDecl != NULL);
- assert(ClassDecl != Declaration);
+ if (ClassDecl == Declaration) {
+ // This can happen for recursive template definitions; if the
+ // current declaration did not match, we can safely return false.
+ assert(TemplateType);
+ return false;
+ }
if (Base.matches(*ClassDecl, this, Builder))
return true;
if (classIsDerivedFrom(ClassDecl, Base, Builder))
Modified: cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp?rev=169262&r1=169261&r2=169262&view=diff
==============================================================================
--- cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp (original)
+++ cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp Tue Dec 4 07:40:29 2012
@@ -232,6 +232,17 @@
"template <> class Z<void> {};"
"template <typename T> class Z : public Z<void>, public X {};",
ZIsDerivedFromX));
+ EXPECT_TRUE(
+ notMatches("template<int> struct X;"
+ "template<int i> struct X : public X<i-1> {};",
+ recordDecl(isDerivedFrom(recordDecl(hasName("Some"))))));
+ EXPECT_TRUE(matches(
+ "struct A {};"
+ "template<int> struct X;"
+ "template<int i> struct X : public X<i-1> {};"
+ "template<> struct X<0> : public A {};"
+ "struct B : public X<42> {};",
+ recordDecl(hasName("B"), isDerivedFrom(recordDecl(hasName("A"))))));
// FIXME: Once we have better matchers for template type matching,
// get rid of the Variable(...) matching and match the right template
More information about the cfe-commits
mailing list