3 ms·
So, is either of these not standard-compliant? I Looked at https://en.cppreference.com/w/cpp/memory/unique_ptr https://en.cppreference.com/w/cpp/memory/unique_p
by Someone 6y ago
So, is either of these not standard-compliant? I Looked at https://en.cppreference.com/w/cpp/memory/unique_ptr https://en.cppreference.com/w/cpp/memory/unique_ptr (yes, I know that’s not the standard, but _I_ trust it to follow it close enough), and couldn’t find evidence for it.
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 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 https://en.cppreference.com/w/cpp/memory/unique_ptr/reset incorrectly, and is some sort of fence implied there?)
- inetknght 6y agounique_ptr does not have an implied fence. atomic<unique_ptr> is what you need if you need a fence. many might argue for shared_ptr but, while it does have a fence, it does _not_ have the same semantics as unique_ptr 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
- anderskaseorg 6y agoThe libstdc++ and libc++ destructors are both standard-compliant (as would be a destructor that doesn’t null the pointer at all) because any program that attempts to observe the difference is wrong. See https://stackoverflow.com/a/66295139/115030 https://stackoverflow.com/a/66295139/115030, https://cplusplus.github.io/LWG/issue2224 https://cplusplus.github.io/LWG/issue2224.