std::swap overloads are UB
Categories
(Core :: MFBT, defect)
Tracking
()
People
(Reporter: mozbugz, Unassigned)
References
(Regression)
Details
(Keywords: regression)
In bug 1609996, some overloads of mozilla::Swap
were replaced with overloads of std::swap
in Atomics.h, Pair.h, and UniquePtr.h.
However, such overloads are explicitly undefined in C++, see http://eel.is/c++draft/namespace.std#1 :
Unless otherwise specified, the behavior of a C++ program is undefined if it adds declarations or definitions to namespace
std
or to a namespace within namespacestd
.
(I've just learnt about this in https://quuxplusone.github.io/blog/2020/07/11/the-std-swap-two-step/ , other details in https://stackoverflow.com/questions/14402990/should-you-overload-swap-in-the-std-namespace )
So these overloads should instead be free functions in their arguments' namespace, which can be found through ADL.
Corresponding call sites may need to be changed to naked swap
s, or two-step using std::swap; swap(...);
in generic code.
But we may actually need to review all explicit std::swap
calls, possibly in a separate bug(?)
Comment 1•5 years ago
|
||
I wonder if this = delete
is meaningful at all: https://searchfox.org/mozilla-central/rev/25d5a4443a7e13cfa58eff38f1faa5e69f0b170f/mfbt/Atomics.h#513
It would be implicitly unavailable if Atomic<T>
were not assignable. But AFAIU it is assignable, and in that case it seems inconsistent to disallow swapping. But maybe it shouldn't be assignable in the first place.
Updated•4 years ago
|
Updated•4 years ago
|
Updated•2 years ago
|
Description
•