The current draft of the C++ standard (march 2019) has the following paragraph ([basic.types] p.4) (emphasis mine):
The object representation of an object of type T is the sequence of N unsigned char objects taken up by the object of type T, where N equals sizeof(T). The value representation of an object of type T is the set of bits that participate in representing a value of type T. Bits in the object representation that are not part of the value representation are padding bits. For trivially copyable types, the value representation is a set of bits in the object representation that determines a value, which is one discrete element of an implementation-defined set of values.
Why is the highlighted sentence limited to trivially copyable types? Is it because some bits from the value representation of a non-trivially-copyable object may be outside its object representation? This answer, as well as this one imply this.
However, in the answers linked above, the conceptual value of the object is based on semantics that are introduced by the user. In the example from the first linked answer:
class some_other_type
{
int a;
std::string s;
};
the user decides that the value of an object of type some_other_type
includes the characters belonging to string s
.
I tried to think of examples where the fact that some bits of an object's (that is not trivially copyable) value representation are outside its object representation is implicit (the implementation has to do this, it is not arbitrarily decided by the user).
One example that I came up with is the fact that the value representation of a base class subobject with virtual methods may include bits from the object representation of the complete object to which it belongs, because the base class subobject may behave differently (may "have a different value") compared to the situation in which it would be a complete object itself.
Another example that I though of is the fact that a vtable may also be part of the value representation of the object whose vtable pointer points to it.
Are these examples correct? Are there other examples?
Was the highlighted sentence introduced by the standard committee because of the fact that the semantic "value" of an object may be decided by the user (as in the two linked answers), or because of the fact that implementations may decide (or may be forced) to do this, or both?
Thank you.
The value representation of an object of type T is the set of bits that participate in representing a value of type T.
I can't make sense of it, other than as a circular definition: the bits that represent the value make up the representation of the value... – Phalanger1110000100010001111
means if its the pattern where a trivially copyable object resides. I.e that the bit pattern is enough to determine the value if you know enough about how an implementation handles bits. – Zink1110000100010001111
means if it were the object representation of a non-trivially-copyable object? Is it because there are some other bits (outside of this object representation) that help decide what value the object has? – Darling