[meta] Remove, or rewrite and document, extensions inside `namespace std`
Categories
(Firefox Build System :: General, task, P3)
Tracking
(Not tracked)
People
(Reporter: mozbugz, Unassigned)
Details
(Keywords: meta)
Extending std
is UB in most cases, with some specified exceptions.
As I write this, there are at least 55 of them in our code: https://searchfox.org/mozilla-central/search?q=namespace+std+{
E.g.:
- Overloading
std::swap
like we do for mozilla::UniquePtr is allowed before C++20, but not working fully as expected. In that case,swap
should be a non-member function in the same namespace as the type, i.e.mozilla::
. More about doing it correctly: https://quuxplusone.github.io/blog/2020/07/11/the-std-swap-two-step/ - OVerloading
std::hash
like we do formozilla::wr::WeSpatialId
is allowed, but it's recommended not to opennamespace std { ... }
, instead overloadstd::hash<...>
directly.
Etc.
I would suggest filing bugs under this one to tackle each of these, or groups thereof.
And wherever we really want to overload something in std::
, it should be explained with a comment.
Here are some more ideas about what can&should be done safely: https://quuxplusone.github.io/blog/2021/10/27/dont-reopen-namespace-std/
Updated•3 years ago
|
Comment 1•2 years ago
|
||
The meta keyword is there, the bug doesn't depend on other bugs and there is no activity for 12 months.
:ahochheiden, maybe it's time to close this bug?
Comment 2•2 years ago
|
||
I think this bug is still valid. It's just that nobody has gotten around to working on it yet.
Comment 3•1 year ago
|
||
The meta keyword is there, the bug doesn't depend on other bugs and there is no activity for 12 months.
:ahochheiden, maybe it's time to close this bug?
Comment 4•1 year ago
|
||
Still valid (36 instances). Same justification as comment 2 for keeping this open.
Description
•