My question is only if

*std::launder(foo_array+5)

is interchangable with:

std::launder(foo_array)[5]


-------- Original Message --------
On Feb 21, 2022, 16:56, < language.lawyer@gmail.com> wrote:

On 22/02/2022 00:35, Ryan Nicholl via Std-Discussion wrote:
> Assuming that we allocate some storage such that there is space for multiple T e.g.
>
> T* foo_array = (T*) malloc(sizeof(foo)*20);
>
> Then if we construct
>
> new (foo_array+5) T(...);
> then
> *std::launder(foo_array+5)
> is valid
>
> But is
>
> std::launder(foo_array)[5]
>
> also valid?

Depends on T. If it is not an implicit-lifetime type, then you would violate https://timsong-cpp.github.io/cppwp/n4868/ptr.launder#2.sentence-2
Also, you don't need std::launder in the first case.