Skip to content

Conversation

@frederick-vs-ja
Copy link
Contributor

On many platforms, we can just reuse the object/value representation of the raw pointer stored within (in)out_ptr_t for operator void**. However, directly use of reinterpret_cast violates the strict aliasing rule ([basic.lval]/11). At the time when out_ptr_t and inout_ptr_t were added to C++23, there was not yet any standard utility bypassing the strict aliasing rule, and thus the notes had to indicate core UB and were only applicable for implementations that didn't aggressively perform type-based aliasing analysis (TBAA).

Luckily, start_lifetime_as was added later, making it possible to reuse value representation without UB. This PR uses start_lifetime_as in the notes, and thus makes them probably applicable for implementations that have compatible representations for T* and void*.

Note that start_lifetime_as can cause conflicts on object creation, but conflicts are already allowed in [out.ptr.t]/5 and [inout.ptr.t]/5.

On many platforms, we can just reuse the object/value representation of
the raw pointer stored within `(in)out_ptr_t` for `operator void**`.
However, directly use of `reinterpret_cast` violates the strict aliasing
rule ([basic.lval]/11). At the time when `out_ptr_t` and `inout_ptr_t`
were added to C++23, there was not yet any standard utility bypassing
the strict aliasing rule, and thus the notes had to indicate core UB and
were only applicable for implementations that didn't aggressively
perform type-based aliasing analysis (TBAA).

Luckily, `start_lifetime_as` was added later, making it possible to
reuse value representation without UB. This PR uses `start_lifetime_as`
in the notes, and thus makes them probably applicable for
implementations that have compatible representations for `T*` and
`void*`.

Note that `start_lifetime_as` can cause conflicts on object creation,
but conflicts are already allowed in [out.ptr.t]/5 and [inout.ptr.t]/5.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant