Title
Copying base classes (PODs) using memcpy
Status
tc1
Section
6.8 [basic.types]
Submitter
Nathan Myers

Created on 1998-09-15.00:00:00 last changed 255 months ago

Messages

Date: 1999-04-15.00:00:00

Proposed Resolution (04/99): Change the text in 6.8 [basic.types] paragraph 2 from:

For any complete POD object type T, ...
to:
For any object (other than a base class subobject) of POD type T, ...
Change the text in 6.8 [basic.types] paragraph 3 from:
For any POD type T, if two pointers to T point to distinct T objects obj1 and obj2,
to:
For any POD 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, ...
Date: 2022-11-20.07:54:16

Can you use memcpy on non-member POD subobjects of non-POD objects?

In 6.8 [basic.types] paragraphs 2 and 3 we have:

For any complete POD object type T, whether or not the object holds a valid value of type T, the underlying bytes (6.7.1 [intro.memory] ) making up the object can be copied into an array of char or unsigned char*. If the content of the array of char or unsigned char is copied back into the object, the object shall subsequently hold its original value. [Example elided]
*[Footnote: By using, for example, the library functions (16.4.2.3 [headers] ) memcpy or memmove. end footnote]
For any POD type T, if two pointers to T point to distinct T objects obj1 and obj2, if the value of obj1 is copied into obj2, using the memcpy library function, obj2 shall subsequently hold the same value as obj1.
Paragraph 3 doesn't repeat the restriction of paragraph 2. Should it be assumed? Otherwise only complete POD types are copyable to an array of char and back, but scribbling over subobjects is OK. (Or perhaps a "distinct T object" is a complete object...)

Proposed Resolution (04/99): Change the text in 6.8 [basic.types] paragraph 2 from:

For any complete POD object type T, ...
to:
For any object (other than a base class subobject) of POD type T, ...
Change the text in 6.8 [basic.types] paragraph 3 from:
For any POD type T, if two pointers to T point to distinct T objects obj1 and obj2,
to:
For any POD 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, ...
History
Date User Action Args
2003-04-25 00:00:00adminsetstatus: dr -> tc1
1999-09-14 00:00:00adminsetmessages: + msg205
1999-09-14 00:00:00adminsetstatus: review -> dr
1998-09-15 00:00:00admincreate