C++ Logo

STD-PROPOSALS

Advanced search

Subject: Re: [std-proposals] Operator functions to fix ADL
From: Jorg Brown (jorg.brown_at_[hidden])
Date: 2020-10-14 09:49:57


> *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_at_[hidden]> 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_at_[hidden]>
> wrote:
>
>> 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
>>
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>



STD-PROPOSALS list run by std-proposals-owner@lists.isocpp.org

Standard Proposals Archives on Google Groups