-
Notifications
You must be signed in to change notification settings - Fork 7
Description
Full name of submitter (unless configured in github; will be published with the issue): C++ community
Reference (section label): [expr.ref]
Issue description:
struct C { int m; };
int i = 0;
int j = reinterpret_cast<C&>(i).m; // the same as `int j = i` ?
Currently, the standard doesn't clearly say that this has undefined behavior. [expr.ref]/(6.2):
If
E2
is a non-static data member and the type ofE1
is “cq1 vq1X
”, and the type ofE2
is “cq2 vq2T
”, the expression designates the corresponding member subobject of the object designated by the first expression
is not very convincing and also can't always be applied to claim UB (when base classes are involved, there is, in some sense, the corresponding member subobject, except that it is at a «wrong offset»).
Suggested resolution:
From https://lists.isocpp.org/core/2020/02/8431.php:
Append to [expr.ref]/7, after the Note:
Similarly, the behavior is undefined if
E2
is a non-static data member or a non-static member function and if the result ofE1
is not an object whose type is the type ofE1
(ignoring cv-qualifications).
(Maybe, «is a non-static data member or a non-static member function» can be just «is a non-static member»)