For a trivially copyable type T consider:
void f(T z)
{
T a;
T b;
std::memcpy(&b, &a, sizeof(T));
a = z;
b = z;
There are a couple things at play here:
unsigned char
(and possibly char
, if unsigned) is the exceptionThis means that
unsigned char
is fine, no matter whether using memcpy
or memmove
or copy-assignment or copy-constructormemcpy
and memmove
is presumably fine for all types, because the result is not "produced by an evaluation" (to meet this requirement, an implementation can use unsigned char
internally, or take advantage of implementation-specific guarantees made for other types)Of course, even the valid methods for copying an indeterminate value create another indeterminate value.
Paragraph numbers correspond to draft n4527