C++ Logo

std-discussion

Advanced search

Re: Is it valid use reinterpret_cast to form pointer to object?

From: Bjorn Reese <breese_at_[hidden]>
Date: Mon, 31 Jul 2023 23:01:11 +0200
On 7/31/23 21:46, Артём Колпаков via Std-Discussion wrote:

> alignas(T) std::byte storage_[sizeof(T)];
> T *ptr_ = ::new (&storage_) T;

Even better: std::construct_at

> *use* reinterpret_cast<T *>(&storage_)
>
> I can't figure out if the second application is valid in general, or is
> it UB? It seems that the standard of the language through prescriptions

Undefined behaviour. See https://wg21.link/p2590

Received on 2023-07-31 21:01:14