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.
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@lists.isocpp.org
https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
--
Std-Proposals mailing list
Std-Proposals@lists.isocpp.org
https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals