https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86908

--- Comment #8 from Kostya Frumkin <fro0m.spam at gmail dot com> ---
> Either way you need to placement new the original type back again, otherwise
> the wrong destructor gets called on scope exit, which adds more undefined
> behaviour.

There should not be undefined behavior because the size of both classes is same
and destructors executes same code (in the case it is noop).
So the memory to be freed up is same.

The behavior must be defined by ISO committee because it is counterintuitive
when the base methods are being called. (where to ask?)

At the same time this design pattern (strategy) with placement-new is more
efficient than with common new. So it has no rationale if the base methods are
used when using placement-new. At the same time other compilers generates code
where the derived method is callsed after placement-new. 

So I see two ways:
- Ask the community to define behavior.
or
- Define behavior in gcc itself.

Reply via email to