Date: Tue, 13 Oct 2020 15:30:13 -0400
On Tue, Oct 13, 2020 at 10:57 AM Dusan Jovanovic (DBJ) <dbj_at_[hidden]> wrote:
> A.O.D. has written: -- I'd be interested to see a compiler patch to warn
> whenever "ADL lookup occurred, on a non-operator, and ADL found a
> best-matching candidate which would *not* have been found by regular
> unqualified lookup." It couldn't be used in production because
> approximately every C++ program depends on ADL *somewhere*. But it could
> give us a sense of the magnitude of the issue. --
>
> Why not just going further: *-fno-adl*
>
> That would certainly "rock the boat". In my not-a-compiler-writer naivete,
> I might think, contrary to A.O.D. (gasp!) a lot of code will work unbroken
> with that switch.? Especially that silent not-minority not using std lib.
>
ADL is used whenever you write
std::string s;
auto t = s + s; // ADL on operator+
std::cout << s; // ADL on operator<<
swap(s, s); // ADL on swap
In particular, the "std::swap two-step" is used inside all swap-based STL
algorithms, such as std::rotate and std::sort.
So you can't actually turn it *off*, because then you'd break the world
(because approximately every C++ program depends on ADL *somewhere*). But
you could issue a warning about it outside of system headers, just to get a
sense of the magnitude of the issue.
–Arthur
> A.O.D. has written: -- I'd be interested to see a compiler patch to warn
> whenever "ADL lookup occurred, on a non-operator, and ADL found a
> best-matching candidate which would *not* have been found by regular
> unqualified lookup." It couldn't be used in production because
> approximately every C++ program depends on ADL *somewhere*. But it could
> give us a sense of the magnitude of the issue. --
>
> Why not just going further: *-fno-adl*
>
> That would certainly "rock the boat". In my not-a-compiler-writer naivete,
> I might think, contrary to A.O.D. (gasp!) a lot of code will work unbroken
> with that switch.? Especially that silent not-minority not using std lib.
>
ADL is used whenever you write
std::string s;
auto t = s + s; // ADL on operator+
std::cout << s; // ADL on operator<<
swap(s, s); // ADL on swap
In particular, the "std::swap two-step" is used inside all swap-based STL
algorithms, such as std::rotate and std::sort.
So you can't actually turn it *off*, because then you'd break the world
(because approximately every C++ program depends on ADL *somewhere*). But
you could issue a warning about it outside of system headers, just to get a
sense of the magnitude of the issue.
–Arthur
Received on 2020-10-13 14:30:28