Date: Sun, 27 Jul 2025 07:42:05 +0200
There is way too many things wrong with your code example. It looks a lot more like the style of C++98. We have moved on from that a long time ago. Maybe we should have said that earlier: we have smart pointers now. If you use them you won’t have any double frees (unless you do something really weird). I’m not sure what the reasons are for adding support to C++ to debug raw pointers that actually manage memory. In modern C++ there is no need for that.
If you want it you should first try to add it to C. They still use raw pointers and it might be useful there. (Also, no destructors und thus no end of lifetimes in the same ways as in C++.) If it is C you might have a chance to adapt it in C++ as well.
> On Jul 27, 2025, at 2:49 AM, Frederick Virchanza Gotham via Std-Proposals <std-proposals_at_[hidden]> wrote:
>
> On Sat, Jul 26, 2025 at 10:54 PM Jonathan Wakely wrote:
>>
>> 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.
>
>
> Are you saying that the following program has undefined behaviour or
> that it's not guaranteed to print "deadbeef"?
>
> https://godbolt.org/z/6bcnz95Ed
>
> Specifically, are you saying that after the MyClass destructor has
> returned, that the first 8 bytes of 'buf' cannot be perused?
>
> And here it is copy-pasted:
>
> char unsigned buf[64u];
>
> struct MyClass {
> int *p = new int;
> ~MyClass(void)
> {
> delete p;
> p = (int*)(void*)0xdeadbeef;
> }
> };
>
> #include <iostream>
> #include <iomanip>
> using std::cout, std::hex, std::endl;
>
> int main(void)
> {
> MyClass *const ptr = static_cast<MyClass*>(static_cast<void*>(&buf));
> ::new(ptr) MyClass;
> ptr->~MyClass();
> // The loop on the next line is for Little Endian CPU's
> for ( unsigned i = 3u; i <= 3u; --i ) cout << hex << (unsigned)buf[i];
> cout << endl;
> }
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
If you want it you should first try to add it to C. They still use raw pointers and it might be useful there. (Also, no destructors und thus no end of lifetimes in the same ways as in C++.) If it is C you might have a chance to adapt it in C++ as well.
> On Jul 27, 2025, at 2:49 AM, Frederick Virchanza Gotham via Std-Proposals <std-proposals_at_[hidden]> wrote:
>
> On Sat, Jul 26, 2025 at 10:54 PM Jonathan Wakely wrote:
>>
>> 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.
>
>
> Are you saying that the following program has undefined behaviour or
> that it's not guaranteed to print "deadbeef"?
>
> https://godbolt.org/z/6bcnz95Ed
>
> Specifically, are you saying that after the MyClass destructor has
> returned, that the first 8 bytes of 'buf' cannot be perused?
>
> And here it is copy-pasted:
>
> char unsigned buf[64u];
>
> struct MyClass {
> int *p = new int;
> ~MyClass(void)
> {
> delete p;
> p = (int*)(void*)0xdeadbeef;
> }
> };
>
> #include <iostream>
> #include <iomanip>
> using std::cout, std::hex, std::endl;
>
> int main(void)
> {
> MyClass *const ptr = static_cast<MyClass*>(static_cast<void*>(&buf));
> ::new(ptr) MyClass;
> ptr->~MyClass();
> // The loop on the next line is for Little Endian CPU's
> for ( unsigned i = 3u; i <= 3u; --i ) cout << hex << (unsigned)buf[i];
> cout << endl;
> }
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
Received on 2025-07-27 05:42:22