CWG Issue 43 (original) (raw)

This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 118e. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2025-11-05


43. Copying base classes (PODs) using memcpy

Section: 6.9 [basic.types]Status: TC1Submitter: Nathan MyersDate: 15 Sep 1998

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

In 6.9 [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.8.1 [intro.memory] ) making up the object can be copied into an array of charor 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 obj1and obj2, if the value of obj1 is copied intoobj2, using the memcpy library function, obj2 shall subsequently hold the same value asobj1.

Paragraph 3 doesn't repeat the restriction of paragraph 2. Should it be assumed? Otherwise only complete POD types are copyable to an array ofchar 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.9 [basic.types] paragraph 2 from:

For any complete POD object type T, ...

to:

For any object (other than a base class subobject) of POD typeT, ...

Change the text in 6.9 [basic.types] paragraph 3 from:

For any POD type T, if two pointers to Tpoint to distinct T objects obj1 and obj2,

to:

For any POD type T, if two pointers to Tpoint to distinct T objects obj1 and obj2, where neither obj1 nor obj2 is a base class subobject, ...