Date: Sun, 27 Jul 2025 22:30:09 +0200
> It's one of those things that isn't guaranteed by any Standard
Then this belongs more into the implementations (e.g. they could overwrite memory of destructed objects with 0xdeadbeef, not just pointer members), and not into standard proposals.
> in real life it works perfectly on every C++ compiler that has ever existed
And possibly could not work any longer with new compiler versions. A good (or not bad) C++ program does not accept UB and is forward-compatible.
The 0xdeadbeef code in the destructor probably is uncritical, as it just further helps with debugging and the correctness of the program does not rely on it. But returning a locked mutex should not rely on UB. (So the standard proposal for factory or any other name of it will help.)
-----Ursprüngliche Nachricht-----
Von:Frederick Virchanza Gotham via Std-Proposals <std-proposals_at_[hidden]>
Gesendet:So 27.07.2025 21:43
Betreff:Re: [std-proposals] Standardising 0xdeadbeef for pointers
An:std-proposals_at_[hidden];
CC:Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>;
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.
--
Std-Proposals mailing list
Std-Proposals_at_[hidden]
https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
Received on 2025-07-27 20:40:06