C++ Logo

std-discussion

Advanced search

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

From: Jason McKesson <jmckesson_at_[hidden]>
Date: Thu, 25 Mar 2021 23:09:31 -0400
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:09:44