Jorg Brown has written: But all you’ve done at that point is demonstrate why people like ADL

Faced with the representative of the people, I better prepare my defence seriously?

“… ADL is widely known to be an essential feature. On the other hand, it is also unarguably a source of many subtle problems…”

Who said that … ;)

ps: sometimes they are not but this wikipedia adl article might be a simple gem.


On Wed, 14 Oct 2020 at 16:49, Jorg Brown <jorg.brown@gmail.com> wrote:
Let's see where that takes us.

OK...

I'm curious how you would re-write Arthur's example without ADL.  It's pretty simple, after all, to write it in such a way that ADL is prevented:

void fn() {
  std::string s;
  auto t = s.operator+(s); // ADL on operator+
  std::cout.operator<<(s); // ADL on operator<<
  (swap)(s, s); // ADL on swap
}

See https://godbolt.org/z/br6K1q

So now what?  How do you accomplish this without ADL?

I mean, you could do it brute-force:

void fn() {
  std::string s;
  auto t = std::operator+(s, s);
  std::operator<<(std::cout, s);
  std::swap(s, s);
}

But all you've done at that point is demonstrate why people like ADL.

-- Jorg


On Tue, Oct 13, 2020 at 4:17 PM Dusan Jovanovic (DBJ) via Std-Proposals <std-proposals@lists.isocpp.org> wrote:
> 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

Perhaps this is why I have written "not-a-minority not using std lib" :) ... you know those pesky C++ projects using -fno-exceptions or even using things like EASTL (gasp! again). I am not a "just-say-no-to-adl" zealot, I am just developing your very same idea further. Let's see where that takes us. Perhaps that might lead to some solution about removing the heavy technical debt of ADL.

Enough said, peace

DBJ



On Tue, 13 Oct 2020 at 21:30, Arthur O'Dwyer <arthur.j.odwyer@gmail.com> wrote:
On Tue, Oct 13, 2020 at 10:57 AM Dusan Jovanovic (DBJ) <dbj@dbj.org> 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
--
Std-Proposals mailing list
Std-Proposals@lists.isocpp.org
https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals