http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49651

           Summary: [C++0x] nested lambdas and -O3 produced incorrect
                    integer variable increments
           Product: gcc
           Version: 4.6.1
            Status: UNCONFIRMED
          Severity: major
          Priority: P3
         Component: c++
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: pedro.lar...@gmail.com


Hi. I'm trying to reproduce this outside 'production' code but haven't been
successful yet. But the observation is the following:

I have 3 level nested lambdas iterating some vectors. Inside, printing and
incrementing this 'sentinel' variable, the output with -O3 shows the wrong
output:

0. sentinel: deadbee5
2. sentinel: deadbee6
1. sentinel: deadbee7
1. sentinel: deadbee8
3. sentinel: deadbee7
4. sentinel: deadbee8
1. sentinel: deadbee9
5. sentinel: deadbee9
6. sentinel: deadbeea
2. sentinel: deadbeeb

With -O0 the values are consecutive. The code is similar to:

u32 sentinel=0xdeadbee0;
auto run = [&](Class& c) {
   for_each(v3.begin(), v3.end(), [&](ClassC& cc) {
       print(sentinel++);
   });
   print(sentinel++);
};
for_each(v.begin(), v.end(), [&](ClassB& b) {

   for_each(v2.begin(), v2.end(), run);
   print(sentinel++);
});


I have observed that the sentinel variable for example, is captured inside the
lambda and the address is not the same as the outermost sentinel...   could
that be the problem that leads to the wrong optimizations?

Reply via email to