llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.09k stars 12k forks source link

Error when explicitly specifying return type of generic lambda in constraint? #115118

Open Eczbek opened 1 week ago

Eczbek commented 1 week ago

https://godbolt.org/z/Yfsdrnn4E

struct foo {
    foo(const foo&) = default;

    foo(auto) requires([]<int = 0> -> bool { return true; }()) {}
};

struct bar { foo x; };

int main() {}
<source>:4:21: error: substitution into constraint expression resulted in a non-constant expression
    4 |         foo(auto) requires([]<int = 0> -> bool { return true; }()) {}
      |                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<source>:1:8: note: while checking constraint satisfaction for template 'foo<foo>' required here
    1 | struct foo {
      |        ^~~
<source>:1:8: note: in instantiation of function template specialization 'foo::foo<foo>' requested here
<source>:7:8: note: while declaring the implicit copy constructor for 'bar'
    7 | struct bar { foo x; };
      |        ^
<source>:4:21: note: undefined function 'operator()<0>' cannot be used in a constant expression
    4 |         foo(auto) requires([]<int = 0> -> bool { return true; }()) {}
      |                            ^
<source>:4:21: note: declared here
<source>:4:21: error: substitution into constraint expression resulted in a non-constant expression
    4 |         foo(auto) requires([]<int = 0> -> bool { return true; }()) {}
      |                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<source>:1:8: note: while checking constraint satisfaction for template 'foo<foo>' required here
    1 | struct foo {
      |        ^~~
<source>:1:8: note: while substituting deduced template arguments into function template 'foo' [with auto:1 = foo]
<source>:7:8: note: while declaring the implicit move constructor for 'bar'
    7 | struct bar { foo x; };
      |        ^
<source>:4:21: note: undefined function 'operator()<0>' cannot be used in a constant expression
    4 |         foo(auto) requires([]<int = 0> -> bool { return true; }()) {}
      |                            ^
<source>:4:21: note: declared here
2 errors generated.
Compiler returned: 1
Eczbek commented 1 week ago

This compiles just fine if I remove -> bool: https://godbolt.org/z/aqGjcrd35

llvmbot commented 1 week ago

@llvm/issue-subscribers-clang-frontend

Author: None (Eczbek)

https://godbolt.org/z/Yfsdrnn4E ```cpp struct foo { foo(const foo&) = default; foo(auto) requires([]<int = 0> -> bool { return true; }()) {} }; struct bar { foo x; }; int main() {} ``` ``` <source>:4:21: error: substitution into constraint expression resulted in a non-constant expression 4 | foo(auto) requires([]<int = 0> -> bool { return true; }()) {} | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ <source>:1:8: note: while checking constraint satisfaction for template 'foo<foo>' required here 1 | struct foo { | ^~~ <source>:1:8: note: in instantiation of function template specialization 'foo::foo<foo>' requested here <source>:7:8: note: while declaring the implicit copy constructor for 'bar' 7 | struct bar { foo x; }; | ^ <source>:4:21: note: undefined function 'operator()<0>' cannot be used in a constant expression 4 | foo(auto) requires([]<int = 0> -> bool { return true; }()) {} | ^ <source>:4:21: note: declared here <source>:4:21: error: substitution into constraint expression resulted in a non-constant expression 4 | foo(auto) requires([]<int = 0> -> bool { return true; }()) {} | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ <source>:1:8: note: while checking constraint satisfaction for template 'foo<foo>' required here 1 | struct foo { | ^~~ <source>:1:8: note: while substituting deduced template arguments into function template 'foo' [with auto:1 = foo] <source>:7:8: note: while declaring the implicit move constructor for 'bar' 7 | struct bar { foo x; }; | ^ <source>:4:21: note: undefined function 'operator()<0>' cannot be used in a constant expression 4 | foo(auto) requires([]<int = 0> -> bool { return true; }()) {} | ^ <source>:4:21: note: declared here 2 errors generated. Compiler returned: 1 ```