Skip to content

Commit 51f1b73

Browse files
jensmaurerzygoloid
authored andcommitted
[ptr.launder] Fix note and example for std::launder.
The applicable rules have changed in response to NB RU 007, US 042 (C++20 CD).
1 parent a930484 commit 51f1b73

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

source/support.tex

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2877,7 +2877,7 @@
28772877
in storage occupied by an existing object of the same type,
28782878
a pointer to the original object
28792879
can be used to refer to the new object
2880-
unless the type contains \tcode{const} or reference members;
2880+
unless its complete object is a const object or it is a base class subobject;
28812881
in the latter cases,
28822882
this function can be used to obtain a usable pointer to the new object.
28832883
See~\ref{basic.life}.
@@ -2886,10 +2886,10 @@
28862886
\pnum
28872887
\begin{example}
28882888
\begin{codeblock}
2889-
struct X { const int n; };
2890-
X *p = new X{3};
2889+
struct X { int n; };
2890+
const X *p = new const X{3};
28912891
const int a = p->n;
2892-
new (p) X{5}; // \tcode{p} does not point to new object\iref{basic.life} because \tcode{X::n} is \tcode{const}
2892+
new (const_cast<X*>(p)) const X{5}; // \tcode{p} does not point to new object\iref{basic.life} because its type is \tcode{const}
28932893
const int b = p->n; // undefined behavior
28942894
const int c = std::launder(p)->n; // OK
28952895
\end{codeblock}

0 commit comments

Comments
 (0)