Skip to content

Lambda evaluated for constant template parameter of function inside templated generic lambda incorrectly complains about local variables needing captures #163837

@MitalAshok

Description

@MitalAshok

This is a reduced example https://godbolt.org/z/WzshaKvxW:

// -std=c++20 -fsyntax-only template<int N> void f(); template<class> struct X { using type = decltype([](auto) { f<[]{ int result = 0; return result; }()>(); }(0)); }; X<void> l;
<source>:9:20: error: variable 'result' cannot be implicitly captured in a lambda with no capture-default specified 9 | return result; | ^ <source>:7:13: note: while substituting into a lambda expression here 7 | f<[]{ | ^ <source>:6:27: note: in instantiation of function template specialization 'X<void>::(anonymous class)::operator()<int>' requested here 6 | using type = decltype([](auto) { | ^ <source>:14:9: note: in instantiation of template class 'X<void>' requested here 14 | X<void> l; | ^ <source>:8:17: note: 'result' declared here 8 | int result = 0; | ^ <source>:7:11: note: lambda expression begins here 7 | f<[]{ | ^ <source>:7:12: note: capture 'result' by value 7 | f<[]{ | ^ | result <source>:7:12: note: capture 'result' by reference 7 | f<[]{ | ^ | &result <source>:7:12: note: default capture by value 7 | f<[]{ | ^ | = <source>:7:12: note: default capture by reference 7 | f<[]{ | ^ | & 

Metadata

Metadata

Assignees

Labels

clang:frontendLanguage frontend issues, e.g. anything involving "Sema"confirmedVerified by a second partylambdaC++11 lambda expressions

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions