On Thu, 19 Sept 2024 at 18:36, François Dumont <[email protected]> wrote:
>
> Thanks for your feedback !
>
> I've applied all your recommendations and it works nicely. Here is the
> test case:
>
> // { dg-do compile }
>
> #include <vector>
> #if __cplusplus >= 201103L
> #include <tuple>
> #endif
>
> struct NoOperators
> {
> };
>
> struct Struct
> {
>    operator std::vector<int>() const;
> } s;
>
> int main()
> {
>    using namespace std;
>
>    bool res __attribute__((unused));
>    res = s == s; // { dg-error "no match" }
>
>    NoOperators s1, s2;
>    res = s1 == s2; // { dg-error "no match" }
>    res = s1 < s2; // { dg-error "no match" }
>    res = s1 != s2; // { dg-error "no match" }
>    res = s1 > s2; // { dg-error "no match" }
>    res = s1 <= s2; // { dg-error "no match" }
>    res = s1 >= s2; // { dg-error "no match" }
> }
>
> // { dg-bogus "candidate" "" { target *-*-* } 0 }
>
> As you can see I've added the test case you provided to show why all
> this is not Standard conformant.
>
> My problem is that if you try to build it without the dg-bogus last
> line, and without my patch, it PASS !
>
> So currently the compiler is not considering the std::vector() cast
> operator to find a == operator on Struct s. If I cast it compiles,
> regardless of std::vector operator == being friend inlined or not.
>
> It doesn't seem to have noticeable effect in this case, does it ?

Hmm, maybe I misremembered why changing non-member operators to hidden
friends is a problem.

I think std::operator==(s, s) will work today, but would fail if it's
a hidden friend.

But maybe https://wg21.link/p3392 will change that.

Reply via email to