Unique_ptr difference between libstdc++ and Libc++ crashes your application
blogs.kde.org
blogs.kde.org
Also note that with libstdc++ that bug is actually a use-after-free bug, which has grave security implications on top of being a regular old bug.
Aside, using a pointer to an object that is destroyed is not always use-after-free. Accessing the value might happen during the destruction, which is the case here or the object can be destroyed, but the memory is not released. "Placement new" and stuff.
Destructor usually call function to unregister themselves from some other places, or free other owned ressources.
I suspect, however, that the standards committee, knowing of this discrepancy, would go with libc++. They explicitly said that reset has to update the pointer before deleting the old object (https://en.cppreference.com/w/cpp/memory/unique_ptr/reset), so one would think they don’t want get() to return the pointer while the unique_pointer destructor is running.
On the other hand, none of that matters in the case if multiple threads or out-of-order CPUs (or do I read https://en.cppreference.com/w/cpp/memory/unique_ptr/reset incorrectly, and is some sort of fence implied there?)
i don't think the problem is libc++ or libstdc++. the problem is, indeed, that KDE is using the unique_ptr after and/or during its lifetime expiration. the immediate fix is indeed as patched, but a better fix would be better management of object lifetimes. good luck getting that done in anything using Qt though
One implementation runs the destructor and then sets the pointer to null -> when code invoked by the destructor accesses the pointer everything still works.
The other implementation sets the pointer to null and then runs the destructor -> when code invoked by the destructor accesses the pointer it gets a null.
I think it is more apt to say that you do not mix libraries with the same names here, or in this case don't mix std library implementations.