C++ Logo

std-discussion

Advanced search

Re: Does destruction clobber storage?

From: Jens Maurer <jens.maurer_at_[hidden]>
Date: Fri, 11 Jul 2025 22:13:51 +0200
On 10.07.25 23:56, Ell via Std-Discussion wrote:
> Here clang bothers to zero out the moved-from unique_ptr, even though it
> knows the subsequent destructor is a nop, while gcc doesn't [1].
> Obviously (?), gcc's behavior is preferable, but is it correct?

A destructed object has ended its lifetime, but the value of an
object is stable only during its lifetime. I think gcc's behavior
is correct (if it isn't, we should change the rules so that it's
correct), and we may have a hole in the core language what happens
to the underlying storage of an object, in general.

Jens


> [1] https://godbolt.org/z/b663K1bnd

Received on 2025-07-11 20:13:58