OK, I see the reason that I disabled templates here. RemoveBaseClass
works in a naive way:
- put all members of a base class to one of its directly derived class;
- remove the base class;
- if the base class has more directly derived classes, then the
previously selected derived class becomes the new base class for those;
Then let's say we have code like below:
class A {}
class B : A {}
class C : A {}
After the transformation, we will have:
class B {}
class C : B {}
Now if B is a template class, RemoveBaseClass will generate incompilable
code like this:
template <class T> class B {};
class C : public B {};
Note that this is just a design choice because RemoveBaseClass doesn't
have sufficient analysis on class hierarchies. If a base class A have a
single derived class, it should be remove even if the derived class is a
template. I will add it into my TODO.
- Yang
Yang Chen wrote:
Hmm, I cannot recall why I did this. I will do some tests and if
thing's going well. I will apply you patch. Thanks!
- Yang
On 10/3/12 3:30 AM, Konstantin Tokarev wrote:
Hi Yang,
Why RemoveBaseClass ignores templates?
I have a test case (attached) which contains redundant base class A,
which is not eliminated by creduce because RemoveBaseClass skips
template classes by design.
After making the next patch it is eliminated:
diff --git a/clang_delta/RemoveBaseClass.cpp
b/clang_delta/RemoveBaseClass.cpp
index 41bae82..219c5d8 100644
--- a/clang_delta/RemoveBaseClass.cpp
+++ b/clang_delta/RemoveBaseClass.cpp
@@ -147,8 +147,7 @@ bool RemoveBaseClass::isDirectlyDerivedFrom(const
CXXRecordDecl *SubC,
void RemoveBaseClass::handleOneCXXRecordDecl(const CXXRecordDecl
*CXXRD)
{
- if (isSpecialRecordDecl(CXXRD) ||
CXXRD->getDescribedClassTemplate() ||
- !CXXRD->hasDefinition())
+ if (isSpecialRecordDecl(CXXRD) || !CXXRD->hasDefinition())
return;