
John Bytheway wrote:
On 22/08/11 16:20, Julian Gonggrijp wrote:
[...] Could you quote the lines from the standard in which memcpy over non-PODs is deemed undefined, just in order for me to know the exact wording?
Well, I can't find it saying that explicitly; indeed there are hardly any mentions on memcpy in the standard at all, but here's a relevant bit for C++0x, from N3290 [basic.types] (3.9) p3:
For any trivially copyable type T, if two pointers to T point to distinct T objects obj1 and obj2, where neither obj1 nor obj2 is a base-class subobject, if the underlying bytes (1.7) making up obj1 are copied into obj2,41 obj2 shall subsequently hold the same value as obj1. [ Example: T* t1p; T* t2p; // provided that t2p points to an initialized object ... std::memcpy(t1p, t2p, sizeof(T)); // at this point, every subobject of trivially copyable type in *t1p contains // the same value as the corresponding subobject in *t2p — end example ]
Interesting. Thank you.