[Bug c++/95349] Using std::launder(p) produces unexpected behavior where (p) produces expected behavior
ed at catmur dot uk
gcc-bugzilla@gcc.gnu.org
Fri May 29 10:59:27 GMT 2020
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95349
--- Comment #9 from Ed Catmur <ed at catmur dot uk> ---
(In reply to Jonathan Wakely from comment #4)
> I don't know the answer, and I don't know why it's useful to try this anyway.
If I'm reading P0593 correctly (I may not be), this would be a valid
implementation of start_lifetime_as:
template<class T>
inline T* start_lifetime_as(void* p) {
std::byte storage[sizeof(T)];
std::memcpy(storage, p, sizeof(T));
auto q = new (p) std::byte[sizeof(T)];
std::memcpy(q, storage, sizeof(T));
auto t = reinterpret_cast<T*>(q);
return std::launder(t);
}
But this has the same issue: https://godbolt.org/z/YYtciP
More information about the Gcc-bugs
mailing list