[g++] inheritance break basic optimisation

Martin v. Loewis martin@mira.isdn.cs.tu-berlin.de
Thu Sep 30 19:57:00 GMT 1999


> I don't know if this is actually a bug, but it seems like to me.
[...]
> So is this normal, does the default copy constructor forbid optimization
> when there is inheritance ?

No, it would be perfectly ok to avoid the multiplication in this case.
So yes, this is a bug - but the reason the compiler does it that way
is probably more complex.

g++ creates a temporary object, which gets optimized-away in one case
but not the other. It always has to write a temporary object into
memory when its address is taken; the address of a C++ object is taken
when a method is called. That appears to happen in one case but not
the other. Most likely, the method being called is the implicit A copy
ctor.

BTW, try compiling your example with -fomit-frame-pointer
-fno-exceptions -fnew-abi. The empty base class optimization of the
new ABI really helps :-)

Regards,
Martin



More information about the Gcc-bugs mailing list