C++ Logo

std-proposals

Advanced search

Re: P1839 and the object representation of subobjects

From: language.lawyer_at <language.lawyer_at_[hidden]>
Date: Tue, 21 Jul 2020 22:51:56 +0300
On 21/07/2020 22:44, language.lawyer_at_[hidden] wrote:> In the code:
>
> QObject *qoptr = ~~~;
> auto c1ptr = reinterpret_cast<C1 *>(
> reinterpret_cast<byte *>(qoptr) + off
> );
> assert(c1ptr == &qoptr->c1);
>
> `reinterpret_cast<byte *>(qoptr) + off` still points to an element of object representation of the `*qoptr` object, not the first element of object representation of its member subobject at the specified offset. P1839R2's changes to reinterpret_cast wording allow conversion between a pointer to an object and its object representation or the first element of its object representation. This code requires std::launder to get a pointer to member subobject.
>
> ...
>
> So, P1839R2 makes well-defined none of the things we're worried about in the context of QProperty.

To be more correct: yes, the behavior of the first code example becomes well-defined in P1839R2, but the behavior is not what is expected.

Received on 2020-07-21 14:55:17