3 ms·
Isn't this exactly what this argument shows? In older versions of C++, if you have an object with a non-const sub-object with a const member, and you give this
by tsimionescu 5y ago
Isn't this exactly what this argument shows? In older versions of C++, if you have an object with a non-const sub-object with a const member, and you give this object to a library, and then that library uses placement new to replace the sub-object within your object, you had to use std::launder to keep referring to the fields of your object, or you'd invoke UB.
In newer C++, thankfully, this is no longer required.
Edit: found a committee paper discussing exactly such cases:
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0532r0.pdf http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p053...
Obj x;
x.use(); // ok
mutate(x); // does this call placement new?
x.use(); // may have undefined behavior
std::launder(&x)->use(); // may be necessary
x.use(); // may still have undefined behavior