http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56901
Bug #: 56901 Summary: [4.9 regression] lambda with implicit capture by reference Classification: Unclassified Product: gcc Version: 4.9.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassig...@gcc.gnu.org ReportedBy: zeratul...@hotmail.com The following code compiles with gcc 4.8 and clang, but not with gcc 4.9: template <typename> void foo_impl() { int data; auto L = [&](){ return data; }; [&](){ L(); }(); } void foo() { foo_impl<int>(); } The error is: test.cpp: In instantiation of 'foo_impl() [with <template-parameter-1-1> = int]::__lambda1': test.cpp:6:12: required from 'struct foo_impl() [with <template-parameter-1-1> = int]::__lambda1' test.cpp:6:19: required from 'void foo_impl() [with <template-parameter-1-1> = int]' test.cpp:11:19: required from here test.cpp:5:14: error: uninitialized const member 'foo_impl() [with <template-parameter-1-1> = int]::__lambda0::__data' auto L = [&](){ return data; }; ^ The error goes away if: - foo_impl is made a nontemplate - the call to the second lambda is inlined - either lambda is made to capture by value instead of reference