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 12:18:12 +0000
On Wed, 29 Nov 2023 at 11:13, Giuseppe D'Angelo via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> Il 29/11/23 11:46, Breno GuimarĂ£es via Std-Proposals ha scritto:
> > I don't think that's UB. Not calling the destructor is not UB.
>
> I was referring to the memset. But indeed I can't seem to find a
> provision that you can't just overwrite bytes of an arbitrary object
> using it. Interesting pub quiz question...
>

There's no guarantee that the bytes of std::future<bool> are contiguous, so
memset could overwrite something that's not part of the object.

And clearly zeroing out the bytes of a std::vector and then expecting it to
keep working afterwards isn't reasonable. I think fiddling with the
underlying bytes is only valid for trivially copyable types.

Received on 2023-11-29 12:18:26