https://bugs.llvm.org/show_bug.cgi?id=46508

            Bug ID: 46508
           Summary: use of overloaded operator '==' is ambiguous (with
                    reversed parameter order)
           Product: clang
           Version: 10.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++2a
          Assignee: unassignedclangb...@nondot.org
          Reporter: derm...@gmail.com
                CC: blitzrak...@gmail.com, erik.pilking...@gmail.com,
                    llvm-bugs@lists.llvm.org, richard-l...@metafoo.co.uk

Hi,

The following code is a very reduced example from a template expression
library:

  class Foo {};

  class X {
  public:
      template <typename T>
      constexpr Foo operator==(const T&) const 
      {
        return Foo{};
      }
  };

  class A : public X {};
  class B : public X {};

  int main() {
    Foo f = A{} == B{};
    return 0;
  }


It fails to compile with C++20:
> clang++-10 -c sample.cpp -std=c++20
  sample.cpp:16:16: error: use of overloaded operator '==' is ambiguous (with
operand types 'A' and 'B')
     Foo f = A{} == B{};
             ~~~ ^  ~~~
  sample.cpp:6:18: note: candidate function [with T = B]
     constexpr Foo operator==(const T&) const
                 ^
  sample.cpp:6:18: note: candidate function (with reversed parameter order)
[with T = A]
  1 error generated.

I can't figure out why the reversed operator is used here (tbh, I'm not a
language lawyer).

Any help is appreciated, thanks!

> clang++-10 --version
clang version 10.0.0-4ubuntu1~18.04.1

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to