C++ Logo

std-proposals

Advanced search

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

From: Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>
Date: Sun, 27 Jul 2025 20:43:34 +0100
On Sun, Jul 27, 2025 at 8:18 PM Sebastian Wittmeier via Std-Proposals
<std-proposals_at_[hidden]> wrote:
>
> Is there any _standard_ reason, why this could not happen with volatile, too?
>
> There is no other volatile operation before the destruction.


It's one of those things that isn't guaranteed by any Standard but
which (probably) works perfectly on every single compiler.

Similar to my solution for returning a locked mutex by value from a function:

    std::mutex Func(void)
    {
        struct Dummy {
            std::mutex m;
            Dummy(void){ m.lock(); }
        };

        constexpr Dummy (*pf)(void) = +[](void){ return Dummy(); };

        auto const pf2 = (std::mutex(*)(void)) pf;

        return pf2();
    }

The above function isn't guaranteed to work at all, it contains
undefined behaviour, but in real life it works perfectly on every C++
compiler that has ever existed.

Received on 2025-07-27 19:43:44