[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
PATCH: "virtual copy constructor" breaks on some platforms
From: |
Matthias Neeracher |
Subject: |
PATCH: "virtual copy constructor" breaks on some platforms |
Date: |
Tue, 22 Mar 2005 17:11:52 -0800 |
While testing with g++ 4.0 on an OS version that shall remain unnamed
and that will be available to the general public in a few months, I
suffered from consistent crashes in Score_engraver::clone(): It
seemed that instead of clone_const_helper, this function called an
entirely unrelated virtual function. It turns out that on this
platform, g++ 4.0 currently has a bug with old style casts that cast
away constness while casting to a non-leftmost base class.
I reported this bug to the appropriate authorities, but on close
examination, it turns out that the entire hair-raising evil of the
VIRTUAL_COPY_CONSTRUCTOR code is not necessary anyway:
#define VIRTUAL_COPY_CONSTRUCTOR(Base, name) \
/* Hack to fix constness: gcc >= 2.95 is correct in defining \
typeof (*this) in a const member function to be const.
*/ \
virtual Base *clone_const_helper () \
{ \
return new name (*this); \
} \
virtual Base *clone () const \
{ \
/* return new name (*this); */ \
Base *urg = (Base *) this; \
return urg->clone_const_helper (); \
return new name (*this); \
}
This is evil because it
a) Uses an old style cast
b) Calls clone_const_helper in the Base class, which if that Base
class is non-leftmost and the leftmost base class has a virtual copy
constructor, will get the wrong instance of clone_const_helper. If
done at all, the cast should have been done to "name *", not "Base *".
It's also completely unnecessary, because the only reason
clone_const_helper was necessary was in conjunction with typeof, and
typeof was eliminated from this code more than a year ago (Revision
1.25).
Patch attached, works fine on the aforementioned platform with g++ 4.0.
Matthias
p
Description: Binary data
- PATCH: "virtual copy constructor" breaks on some platforms,
Matthias Neeracher <=