forked from OSchip/llvm-project
[ASTMatchers] Fix isDerivedFrom for recursive templates
Differential Revision: https://reviews.llvm.org/D77612
This commit is contained in:
parent
7b6ff8bf1f
commit
14d89bfbe0
|
@ -916,9 +916,8 @@ bool MatchASTVisitor::classIsDerivedFrom(const CXXRecordDecl *Declaration,
|
||||||
if (!ClassDecl)
|
if (!ClassDecl)
|
||||||
continue;
|
continue;
|
||||||
if (ClassDecl == Declaration) {
|
if (ClassDecl == Declaration) {
|
||||||
// This can happen for recursive template definitions; if the
|
// This can happen for recursive template definitions.
|
||||||
// current declaration did not match, we can safely return false.
|
continue;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
BoundNodesTreeBuilder Result(*Builder);
|
BoundNodesTreeBuilder Result(*Builder);
|
||||||
if (Base.matches(*ClassDecl, this, &Result)) {
|
if (Base.matches(*ClassDecl, this, &Result)) {
|
||||||
|
|
|
@ -453,6 +453,20 @@ TEST(DeclarationMatcher, ClassIsDerived) {
|
||||||
EXPECT_TRUE(notMatches("class X;", IsDerivedFromX));
|
EXPECT_TRUE(notMatches("class X;", IsDerivedFromX));
|
||||||
EXPECT_TRUE(notMatches("class Y;", IsDerivedFromX));
|
EXPECT_TRUE(notMatches("class Y;", IsDerivedFromX));
|
||||||
EXPECT_TRUE(notMatches("", IsDerivedFromX));
|
EXPECT_TRUE(notMatches("", IsDerivedFromX));
|
||||||
|
EXPECT_TRUE(matches("class X {}; template<int N> class Y : Y<N-1>, X {};",
|
||||||
|
IsDerivedFromX));
|
||||||
|
EXPECT_TRUE(matches("class X {}; template<int N> class Y : X, Y<N-1> {};",
|
||||||
|
IsDerivedFromX));
|
||||||
|
|
||||||
|
DeclarationMatcher IsZDerivedFromX = cxxRecordDecl(hasName("Z"),
|
||||||
|
isDerivedFrom("X"));
|
||||||
|
EXPECT_TRUE(
|
||||||
|
matches(
|
||||||
|
"class X {};"
|
||||||
|
"template<int N> class Y : Y<N-1> {};"
|
||||||
|
"template<> class Y<0> : X {};"
|
||||||
|
"class Z : Y<1> {};",
|
||||||
|
IsZDerivedFromX));
|
||||||
|
|
||||||
DeclarationMatcher IsDirectlyDerivedFromX =
|
DeclarationMatcher IsDirectlyDerivedFromX =
|
||||||
cxxRecordDecl(isDirectlyDerivedFrom("X"));
|
cxxRecordDecl(isDirectlyDerivedFrom("X"));
|
||||||
|
|
Loading…
Reference in New Issue