https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70121
Bug ID: 70121 Summary: spurious warning and crash when returning a reference from lambda Product: gcc Version: 5.3.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: blastrock at free dot fr Target Milestone: --- When I try to compile this simple program with gcc 5.3.1: #include <functional> int main(int argc, char *argv[]) { const int val = 28; auto ff = [&]() -> const int& { return val; }; int i = ff(); } with the argument -std=c++11, I get the following warning: warning: returning reference to temporary [-Wreturn-local-addr] And the program crashes on the int assign statement. I believe this code is legal, the temporary variable is still valid when the lambda is called. And the same code compiles without warning and runs without crash with clang 3.7.