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]

Reply via email to