[Bug c++/60096] New: c++11 lambda reference capture mistake
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60096 Bug ID: 60096 Summary: c++11 lambda reference capture mistake Product: gcc Version: 4.8.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: feng.w...@uni-ulm.de considering the following code: [code] #include iostream int main() { std::cout []( int x ) { return [](int y) { return x+y; }(2); }(5) \n; std::cout []( int x ) { return [x](int y) { return x+y; }; }(2)(5) \n; std::cout []( int x ) { return [x](int y) { return x+y; }; }(2)(5) \n; return 0; } [/code] the output produced by g++4.8 and g++4.9 is [output] 7 10 7 [/output] while the expected output is [output] 7 7 7 [/output]
[Bug c++/60096] c++11 lambda reference capture mistake
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60096 --- Comment #2 from Feng Wang feng.w...@uni-ulm.de --- (In reply to Jonathan Wakely from comment #1) This looks invalid to me, you return a closure that holds a dangling reference to a function parameter that has gone out of scope. Sorry, my fault. I should have been using a const reference []( int const x ) { return [x](int const y) { return x+y; }; } (2)(5);
[Bug c++/60096] c++11 lambda reference capture mistake
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60096 Feng Wang feng.w...@uni-ulm.de changed: What|Removed |Added Status|UNCONFIRMED |RESOLVED Resolution|--- |INVALID --- Comment #3 from Feng Wang feng.w...@uni-ulm.de --- mark as invalid.