Skip to content

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

Open
@Eczbek

Description

@Eczbek

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:frontendLanguage frontend issues, e.g. anything involving "Sema"conceptsC++20 conceptslambdaC++11 lambda expressions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions