C++ Logo

std-proposals

Advanced search

Re: [std-proposals] void std::optional<T>::abandon(void) noexcept

From: Jonathan Wakely <cxx_at_[hidden]>
Date: Wed, 29 Nov 2023 11:11:51 +0000
On Wed, 29 Nov 2023 at 10:47, Breno GuimarĂ£es via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> I don't think that's UB. Not calling the destructor is not UB.
>

It's not explicitly stated, but I think it's safe to say that using memset
to write the bytes of a class should follow the same rules as memcpy, which
is undefined unless the type is trivially copyable.


>
> Em qua., 29 de nov. de 2023 07:40, Giuseppe D'Angelo via Std-Proposals <
> std-proposals_at_[hidden]> escreveu:
>
>> Il 29/11/23 11:28, Frederick Virchanza Gotham via Std-Proposals ha
>> scritto:
>> > But of course the details of my project aren't particularly relevant
>> > here on this mailing list -- the principle here is that sometimes,
>> > although rarely, you want to just give up on an object and forget
>> > about destroying it.
>>
>> Jonathan Wakely already gave you the solution: allocate it on the heap,
>> and then leak it if things to wrong.
>>
>> > For now I think I'll just do:
>> >
>> > memset( &obj.value(), 0, sizeof obj.value() ); // not needed
>> > but paranoia is good
>> > ::new( &obj.value() ) std::future<bool>();
>>
>> This is outright UB. That's nowhere an acceptable tradeoff.
>>
>> My 2 c,
>> --
>> Giuseppe D'Angelo
>> --
>> Std-Proposals mailing list
>> Std-Proposals_at_[hidden]
>> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>>
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>

Received on 2023-11-29 11:12:06