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

            Bug ID: 108579
           Summary: Requires-expression that checks constructor on
                    non-template constructor of template class got
                    rejected
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gnaggnoyil at gmail dot com
  Target Milestone: ---

template <typename T>
class foo{
public:
    foo(double, char){}
    foo(int) requires requires { foo(0.0, 'c'); }{}
};

int main(){
    foo<int> x(3);
    (void)x;
    return 0;
}

The above code fails to compile on latest GCC trunk with `-std=c++20` as of the
day of report:

test8.cpp: In instantiation of ‘foo<T>::foo(int) requires requires{foo(0.0,
'c');} [with T = int]’:
test8.cpp:9:17:   required from here
test8.cpp:5:5:   required by the constraints of ‘template<class T>
foo<T>::foo(int) requires requires{foo(0.0, 'c');}’
test8.cpp:5:23:   in requirements  [with T = int]
test8.cpp:5:23: error: satisfaction value of atomic constraint
‘requires{foo(0.0, 'c');} [with T = int]’ changed from ‘false’ to ‘true’
    5 |     foo(int) requires requires { foo(0.0, 'c'); }{}
      |                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~
test8.cpp:2:7: note: satisfaction value first evaluated to ‘false’ from here
    2 | class foo{
      |       ^~~
test8.cpp: In function ‘int main()’:
test8.cpp:9:17: error: no matching function for call to ‘foo<int>::foo(int)’
    9 |     foo<int> x(3);
      |                 ^
test8.cpp:5:5: note: candidate: ‘foo<T>::foo(int) requires requires{foo(0.0,
'c');} [with T = int]’
    5 |     foo(int) requires requires { foo(0.0, 'c'); }{}
      |     ^~~
test8.cpp:5:5: note: constraints not satisfied
test8.cpp:4:5: note: candidate: ‘foo<T>::foo(double, char) [with T = int]’
    4 |     foo(double, char){}
      |     ^~~
test8.cpp:4:5: note:   candidate expects 2 arguments, 1 provided
test8.cpp:2:7: note: candidate: ‘constexpr foo<int>::foo(const foo<int>&)’
    2 | class foo{
      |       ^~~
test8.cpp:2:7: note:   no known conversion for argument 1 from ‘int’ to ‘const
foo<int>&’
test8.cpp:2:7: note: candidate: ‘constexpr foo<int>::foo(foo<int>&&)’
test8.cpp:2:7: note:   no known conversion for argument 1 from ‘int’ to
‘foo<int>&&’

Replacing the "requires {}" part with "is_constructible<foo, double, char>"
will get rejected too, but with different error messages.

Prior releases of GCC like 12.1 or 12.2 can accept both programs without any
problem.

Reply via email to