Skip to content

Commit 44c228d

Browse files
[out.ptr.t][inout.ptr.t] Get rid of TBAA-violating implication
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.
1 parent 3186be7 commit 44c228d

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

source/memory.tex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5509,7 +5509,7 @@
55095509

55105510
\pnum
55115511
\begin{note}
5512-
\tcode{reinterpret_cast<void**>(static_cast<Pointer*>(*this))}
5512+
\tcode{start_lifetime_as<void*>(\&const_cast<Pointer\&>(p))}
55135513
can be a viable implementation strategy for some implementations.
55145514
\end{note}
55155515
\end{itemdescr}
@@ -5745,7 +5745,7 @@
57455745

57465746
\pnum
57475747
\begin{note}
5748-
\tcode{reinterpret_cast<void**>(static_cast<Pointer*>(*this))}
5748+
\tcode{start_lifetime_as<void*>(\&const_cast<Pointer\&>(p))}
57495749
can be a viable implementation strategy for some implementations.
57505750
\end{note}
57515751
\end{itemdescr}

0 commit comments

Comments
 (0)