As far as I am aware, memcpy
into uninitialized storage cannot safely be used to create an copy of the source object.
However, in this thread from last year on the open-std WG21 "ub" list, a participant refers to the new memcpy lifetime-initiation rules:
This doesn’t seem to rise to the level of a bug report, but it might be relevant to the new memcpy lifetime-initiation rules. Will they ascribe some static type to the source and destination bytes?
Based on the context of the question and small amount of type-erasure example code, it appears that it may be related to creating new objects in aligned_storage
via memcpy
.
Search as I might, I can't find a reference to the new rules. I'm particularly curious if they only apply to replacing the contents of an already created object, or if they change the situation around the potential creation of an object in uninitialized memory.