C++ Logo

std-discussion

Advanced search

Re: std::launder question

From: Peter C++ <peter.cpp_at_[hidden]>
Date: Tue, 22 Feb 2022 07:33:35 +0100
it seems to me using an index 5 on an array of size 5 is at least UB anyway.

Sent from Peter Sommerlad's iPad
+41 79 432 23 32

> On 21 Feb 2022, at 22:56, language.lawyer--- via Std-Discussion <std-discussion_at_[hidden]> 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.
> --
> Std-Discussion mailing list
> Std-Discussion_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-discussion

Received on 2022-02-22 06:37:01