File tree Expand file tree Collapse file tree 1 file changed +4
-4
lines changed
Expand file tree Collapse file tree 1 file changed +4
-4
lines changed Original file line number Diff line number Diff line change 28772877in storage occupied by an existing object of the same type,
28782878a pointer to the original object
28792879can 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 ;
28812881in the latter cases,
28822882this function can be used to obtain a usable pointer to the new object.
28832883See~\ref {basic.life }.
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};
28912891const 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}
28932893const int b = p->n; // undefined behavior
28942894const int c = std::launder(p)->n; // OK
28952895\end {codeblock }
You can’t perform that action at this time.
0 commit comments