Full name of submitter: Andrey Erokhin
Reference (section label): [basic.types.general] [basic.compound]
Link to reflector thread (if any): -
Issue description:
(Wanted to file the issue for many years)
[basic.types.general] says:
For trivially copyable types, the value representation is a set of bits in the object representation that determines [emphasis mine] a value, which is one discrete element of an implementation-defined set of values.
For pointers, bits in their representation can't determine the value.
A simple example:
int a[2][2];
int* p1 = &a[0][2];
int* p2 = &a[1][0];
p1 and p2 usually have the same bits in their representation, but they are different values.
And, ofc, one can produce arbitrary number of pointer values with the same representation, but different values by replacing an object:
int i;
int* p1 = &i;
std::byte buf[sizeof(p1)];
std::memcpy(buf, &p1, sizeof(p1)); // save the value
int* p2 = ::new(&i) int; // rebinds p1 (is it a write to p1?)
std::memcpy(&p1, buf, sizeof(p1)); // restore p1 value
p1 and p2 point to different objects (thus have different values), but bits in their representation are usually the same
Suggested resolution:
Exclude pointers from trivially copyable types
Full name of submitter: Andrey Erokhin
Reference (section label): [basic.types.general] [basic.compound]
Link to reflector thread (if any): -
Issue description:
(Wanted to file the issue for many years)
[basic.types.general] says:
For pointers, bits in their representation can't determine the value.
A simple example:
p1andp2usually have the same bits in their representation, but they are different values.And, ofc, one can produce arbitrary number of pointer values with the same representation, but different values by replacing an object:
p1andp2point to different objects (thus have different values), but bits in their representation are usually the sameSuggested resolution:
Exclude pointers from trivially copyable types