logoalt Hacker News

jandrewrogersyesterday at 3:19 PM2 repliesview on HN

There was already a legal way to achieve this that everyone should already have been using (laundering a pointer through a no-op memmove). Using reinterpret_cast here is a bug.

The "start_lifetime_as" facility does one additional thing beyond providing a tidy standard name for the memory laundering incantation. Semantically it doesn't touch the memory whereas the no-op memmove intrinsically does. In practice, this makes little difference, since the compiler could see that the memmove was a no-op and optimized accordingly.


Replies

kevin_thibedeauyesterday at 3:38 PM

This still has unresolved alignment issues that blow up outside the amd64 ecosystem.

show 1 reply
szmarczakyesterday at 3:40 PM

No because the object does not exist after std::launder. It only exists after std::start_lifetime_as. The bytes being there says nothing about the object, per the C++ standard.

show 1 reply