Re: aliasing rules and delete operator
Joergen Samson <joergen.samson@desy.de> writes:
So you are suggesting to write:
inline void myClass::operator delete(void *b)
{
Link* p = new(b) Link;
p->next = head;
head= p;
}
Well, that makes sense, actually. It's more descriptive than the
original code and should probably be as optimal as that, because Link
has a trivial constructor. It would be interesting to know if this code
still triggers the gcc optimizer bug...
Although the code with the placement new seems to be much cleaner than
using a static_cast, the code with the placement new also crashes.
It really seems to me, that the whole problem boils down to the
question, whether the original object "is still an object" when the
delete operator is called.
I managed to write a minimal example that illustrates the problem. This
might help you to explore this "feature" of the gcc in detail.
If you compile this example with a gcc >= 3.3.3 the program will crash
with an segmentation fault.
I can reproduce the crash with GCC 3.3.6, but I can't reproduce it with
either of 3.4.6, 4.0.4, or 4.1.2 on my Debian Linux x86 box. Compiled as
g++ -O3 -o crash crash.cc
So it seems that this has been fixed in recent GCC versions.
--
Sergei.
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]