https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118677

            Bug ID: 118677
           Summary: Operator auto() requires () selects wrong overload
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: egor.pugin at gmail dot com
  Target Milestone: ---

https://godbolt.org/z/Wsa9fPWjc

Clang seems ok.

==============================

template <auto Bytes>
struct A {
    operator auto() requires (Bytes == 3) { return 3; }
    operator auto() requires (Bytes != 3) { return 2; }
};

int main() {
    A<2> a;
    return a;
}

==============================

<source>: In function 'int main()':
<source>:9:12: error: use of function 'A<Bytes>::operator auto() requires 
Bytes == 3 [with auto Bytes = 2]' with unsatisfied constraints
    9 |     return a;
      |            ^
<source>:3:5: note: declared here
    3 |     operator auto() requires (Bytes == 3) { return 3; }
      |     ^~~~~~~~
<source>:3:5: note: constraints not satisfied
<source>: In instantiation of 'A<Bytes>::operator auto() requires  Bytes == 3
[with auto Bytes = 2]':
<source>:9:12:   required from here
    9 |     return a;
      |            ^
<source>:3:5:   required by the constraints of 'template<auto Bytes>
A<Bytes>::operator auto() requires  Bytes == 3'
<source>:3:37: note: the expression 'Bytes == 3 [with Bytes = 2]' evaluated to
'false'
    3 |     operator auto() requires (Bytes == 3) { return 3; }
      |                              ~~~~~~~^~~~~
<source>:9:12: error: use of function 'A<Bytes>::operator auto() requires 
Bytes == 3 [with auto Bytes = 2]' with unsatisfied constraints
    9 |     return a;
      |            ^
<source>:3:5: note: declared here
    3 |     operator auto() requires (Bytes == 3) { return 3; }
      |     ^~~~~~~~
<source>:3:5: note: constraints not satisfied
<source>: In instantiation of 'A<Bytes>::operator auto() requires  Bytes == 3
[with auto Bytes = 2]':
<source>:9:12:   required from here
    9 |     return a;
      |            ^
<source>:3:5:   required by the constraints of 'template<auto Bytes>
A<Bytes>::operator auto() requires  Bytes == 3'
<source>:3:37: note: the expression 'Bytes == 3 [with Bytes = 2]' evaluated to
'false'
    3 |     operator auto() requires (Bytes == 3) { return 3; }
      |                              ~~~~~~~^~~~~

Reply via email to