[llvm-bugs] [Bug 51291] New: Wrong program output in case of many concept conversion operators

via llvm-bugs llvm-bugs at lists.llvm.org
Sat Jul 31 01:49:21 PDT 2021


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

            Bug ID: 51291
           Summary: Wrong program output in case of many concept
                    conversion operators
           Product: clang
           Version: 12.0
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: fchelnokov at gmail.com
                CC: blitzrakete at gmail.com, dgregor at apple.com,
                    erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
                    richard-llvm at metafoo.co.uk

Example code:
```
template <auto =[]{}> class C;
template <typename, typename = C<>> concept x = true;

#include <iostream>

struct S {
    operator x<C<>> auto() { return 42; }
    operator x<C<>> auto() { return '+'; }
    operator x<C<>> auto() { return 44LL; }
    operator x<C<>> auto() { return 45.5; }
    operator x<C<>> auto() { return 46.5f; }
    operator x<C<>> auto() { return 47L; }    
    operator x<C<>> auto() { return 48ULL; }
    operator x<C<>> auto() { return 49U; }
};

int main() {
    S s;
    std::cout << (int)s << "\n";
    std::cout << (char)s << "\n";
    std::cout << (long long)s << "\n";

    std::cout << (double)s << "\n";
    std::cout << (float)s << "\n";
    std::cout << (long)s << "\n";

    std::cout << (unsigned long long)s << "\n";
    std::cout << (unsigned)s << "\n";
}
```

Clang prints here:
```
49
1
49
0
0
49
49
49
```
which is obviously wrong.

Demo: https://gcc.godbolt.org/z/dPa4GxYhc

-- 
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/20210731/413ce41b/attachment.html>


More information about the llvm-bugs mailing list