https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95086
Bug ID: 95086 Summary: brace initialization in captures doesn't work with function calls Product: gcc Version: 11.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: nico at josuttis dot de Target Milestone: --- AFAIK, since C++17 we should be able to do: [&coll{std::as_const(vec)}] {} but it doesn't compile: prog.cc: In function 'int main()': prog.cc:10:44: error: cannot capture '{std::as_const<std::vector<int> >(vec)}' by reference 10 | [&coll{std::as_const(vec)}] { // ERROR??? | ^ However, both using = for the initialization: [&coll = std::as_const(vec)] { and for simple initializations using braces: [max{42}] { work fine. Other compilers do it as I expect. It seems to be a problem when reference captures are initialized by function calls (or other expressions). See https://wandbox.org/permlink/LMSfQ1nLszVHQ4LF