[Bug c++/95349] Using std::launder(p) produces unexpected behavior where (p) produces expected behavior

richard-gccbugzilla at metafoo dot co.uk gcc-bugzilla@gcc.gnu.org
Fri May 29 18:07:16 GMT 2020


--- Comment #16 from Richard Smith <richard-gccbugzilla at metafoo dot co.uk> ---
Per p0593, memcpy implicitly creates objects (of any implicit lifetime type) in
the destination. It does not propagate the objects in the source memory to the
destination memory, and can therefore be used to perform a bit cast. (This is
different from C, where memcpy either preserves or copies the effective type
depending on whether the destination has a declared type.)

The s3 function in comment#1 looks correct to me (with or without the launder).
Optimizing it to { return (uint64t *)p; } is incorrect, because it loses the
erasure of dynamic type information that p0593 requires from memcpy in C++.

More information about the Gcc-bugs mailing list