Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2022-02-18 16:36:12


Andrey Semashev wrote:
> What std::launder is intended to be is a fence for compiler speculations as to
> the possible value in the dereferenced location. That is, in the following
> example:
>
> alignas(int) unsigned char storage[sizeof(int)];
> int* p1 = new (storage) int(1);
> float* p2 = new (storage) float(2.0f);
> int* p3 = new (storage) int(3);
> std::printf("%d\n", *p1);
>
> the program is allowed to print 1...

I don't think it is. The "will automatically apply to the new object" clause
applies (even in its C++14 form) and all its requirements seem to be met.
https://eel.is/c++draft/basic.life#8


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk