C++ Logo

std-discussion

Advanced search

Re: Implicit object creation, arrays, and non-implicit lifetime objects

From: language.lawyer_at <language.lawyer_at_[hidden]>
Date: Fri, 26 Mar 2021 06:45:25 +0300
https://github.com/cplusplus/draft/issues/4553

On 26/03/2021 06:09, Jason McKesson via Std-Discussion wrote:
> Indeed, I found an interesting problem here. In the allocator
> requirements `a.allocate`, the standard says that the following code
> can be used to create an array of `T` within the storage `p` without
> necessarily creating `T`s, as well as retrieving a pointer to the
> first `T`:
>
> ```
> launder(reinterpret_cast<T*>(new (p) byte[n * sizeof(T)]))
> ```
>
> But we know that doesn't work because `launder` *requires* that there
> must be a `T` *within its lifetime* in that memory. And if `T` is not
> an ILT, then (according to that notation), it shouldn't be within its
> lifetime.
>

Received on 2021-03-25 22:45:30