C++ Logo

sg12

Advanced search

Re: [ub] launder and aliasing

From: Robert Haberlach <rh633_at_[hidden]>
Date: Sun, 28 Feb 2016 11:18:26 +0000
On 2/26/2016 9:46 PM, Richard Smith wrote:
> I don't think that is the right interface for such functionality. No matter what you do with the pointer, if you create a situation where an int*
> and a float* can simultaneously exist and both can be used to load or store the same memory, you destroy TBAA.
I see.

I take it that the placement new in your example is necessary to apply [basic.life]/7, as we wouldn't otherwise be able to obtain a pointer actually
pointing to the last created object of type T (or more fundamentally, a memcpy does not eo ipso create an object of a different type in the target
memory location). However, this requires default constructability. Is there a way to "inject" the new type without necessitating a default constructor
call?

IIRC there was a paper suggesting a construct that performs such vacuous "initialization" (demonstrated using __cookie__ as an initializer), but I
can't find it at the moment.

Also, I don't see the point of p->~U(). Isn't U::~U trivial by assumption?

Received on 2016-02-28 12:18:47