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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |rguenth at gcc dot gnu.org

--- Comment #6 from Richard Biener <rguenth at gcc dot gnu.org> ---
(In reply to Jonathan Wakely from comment #1)
> No, your program has undefined behaviour. To make it valid you either need
> to use std::launder, or use the pointer that is returned by the placement
> new.
> 
> The compiler is allowed to assume that the dynamic type of &strategy does
> not change (that's why you need to use std::launder).

You need to use std::launder at every use of the object, right?  I wonder
why static_cast<BaseStrategy*>() isn't a good enough "hint" here that
the type of strategy changed (from QOI perspective, std::launder is new).

I guess a better testcase would be to declare strategy as AStrategy
and placement-new BaseStrategy over it or does the standard guaranteee
that AStrategy fits in the storage of BaseStrategy?

Reply via email to