C++ Logo

std-proposals

Advanced search

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

From: Giuseppe D'Angelo <giuseppe.dangelo_at_[hidden]>
Date: Wed, 29 Nov 2023 11:40:16 +0100
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

Received on 2023-11-29 10:40:19