This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/53488] New: Incorrect code generated when capturing a constant by reference in a lambda


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]