Missed optimization with const member
Ion Gaztañaga
igaztanaga@gmail.com
Fri Jul 7 12:26:00 GMT 2017
On 05/07/2017 17:24, Martin Sebor wrote:
> [*] While the example (copied below) is valid, accessing the object
> after someFunction() has returned via a reference or pointer to it
> is not.
>
> void somefunction(const Object& object);
> {
> void* p = &object;
> object.~Object();
> new(p) Object();
> }
I think it's problematic as explained in p0532r0.pdf. We construct and
destroy objects in the internal buffer of std::vector and we don't
update the pointer every time. I don't see myself understanding when
std::launder must be used, looks too expert-grade feature.
Best,
Ion
More information about the Gcc
mailing list