C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Standardising 0xdeadbeef for pointers

From: Jonathan Wakely <cxx_at_[hidden]>
Date: Sat, 26 Jul 2025 23:53:38 +0200
On Sat, 26 Jul 2025, 22:58 Tiago Freire via Std-Proposals, <
std-proposals_at_[hidden]> wrote:

> Were in the standard does it prescribe that the memory cannot be
> overwritten after the destructor is complete?
>
> in normal circumstances the memory is not even guaranteed to be
> accessible. Except perhaps in placement new, now your contrived use case is
> placement new only?
>

There's nothing special about placement new in this regard. Any value
written to a non-static data member by the destructor is a dead store, it
cannot be read after the destructor finishes. It is irrelevant whether the
object was initialized using placement new.

As it's a dead store, the compiler can remove that store completely. So
writing a badptr value would be optimised away for most builds, and only
meaningful for unoptimized builds. Which is another reason it makes no
sense in the standard.

Just use address sanitizer (which is not "GNU address sanitizer", it had
nothing to do with the GNU project, it originated in llvm and was written
at Google).

Received on 2025-07-26 21:53:57