http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53488
Bug #: 53488 Summary: Incorrect code generated when capturing a constant by reference in a lambda Classification: Unclassified Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassig...@gcc.gnu.org ReportedBy: jpale...@web.de Created attachment 27497 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=27497 Preprocessed source I have the following source: jirka@debian:~/benchmark$ cat error.cpp #include <iostream> template<class T> void f() { const int i=sizeof(T); auto fun = [&] { std::cout << i << std::endl; }; fun(); } int main() { f<double>(); return 0; } When I compile and run this program, it outputs garbage (instead of sizeof(double)): jirka@debian:~/benchmark$ g++-4.7 --std=c++0x error.cpp jirka@debian:~/benchmark$ ./a.out 134514706 Changing f to a nontemplate, i to be nondependent ot captured by value produces correct output.