https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114183
Bug ID: 114183 Summary: Lambda constexpr works in msvc but not in gcc Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: jlame646 at gmail dot com Target Milestone: --- The following valid(afaik) program is rejected by gcc: https://godbolt.org/z/xhes5fvoc ``` int main() { constexpr auto func = []()constexpr { return 1; }; auto i = []{return func();}; } ``` GCC says: ``` <source>: In lambda function: <source>:3:28: error: 'func' is not captured 3 | auto i = []{return func();}; | ~~~~^~ <source>:3:15: note: the lambda has no capture-default 3 | auto i = []{return func();}; | ^ <source>:2:20: note: 'constexpr const main()::<lambda()> func' declared here 2 | constexpr auto func = []()constexpr { return 1; }; | ``` https://en.cppreference.com/w/cpp/language/lambda says: > A lambda expression can read the value of a variable without capturing it if > the variable > is constexpr and has no mutable members.