[llvm-bugs] [Bug 44627] New: Reversed candidate operator is not found by argument dependent lookup

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Jan 22 15:08:42 PST 2020


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

            Bug ID: 44627
           Summary: Reversed candidate operator is not found by argument
                    dependent lookup
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++2a
          Assignee: unassignedclangbugs at nondot.org
          Reporter: david at doublewise.net
                CC: blitzrakete at gmail.com, erik.pilkington at gmail.com,
                    llvm-bugs at lists.llvm.org, richard-llvm at metafoo.co.uk

The following code

```
namespace n {

struct type {};

bool operator==(type lhs, int rhs) {
        return true;
}

} // namespace n

void f() {
    n::type() == 0;
    0 == n::type(); // fails
}
```

fails to compile with the error message

```
<source>:13:7: error: invalid operands to binary expression ('int' and
'n::type')

    0 == n::type(); // fails

    ~ ^  ~~~~~~~~~

<source>:5:6: note: candidate function not viable: no known conversion from
'int' to 'n::type' for 1st argument

bool operator==(type lhs, int rhs) {

     ^

1 error generated.

Compiler returned: 1
```

when compiled against clang trunk with `clang++ -std=c++2a -stdlib=libc++ -w`.
The same thing occurs for `<=>` and the other comparison operators. Note that
it succeeds if the definition of `f` is moved into `n`.

See it live: https://godbolt.org/z/pHwvw6

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20200122/1bddfe30/attachment.html>


More information about the llvm-bugs mailing list