This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/53488] New: Incorrect code generated when capturing a constant by reference in a lambda
- From: "jpalecek at web dot de" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 25 May 2012 16:04:05 +0000
- Subject: [Bug c++/53488] New: Incorrect code generated when capturing a constant by reference in a lambda
- Auto-submitted: auto-generated
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: unassigned@gcc.gnu.org
ReportedBy: jpalecek@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.