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 tree-optimization/49651] [C++0x] nested lambdas and -O3 produced incorrect integer variable increments


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

--- Comment #7 from Richard Guenther <rguenth at gcc dot gnu.org> 2011-07-13 12:31:13 UTC ---
Further reduced (-O2 vs. -O1):

#include <vector>
#include <algorithm>

extern "C" void abort (void);

typedef unsigned int u32;
using namespace std;
vector<u32> g;
void f(u32 b)
{
  g.push_back(b);
  for(int i=1; i<g.size() && ! g.empty(); ++i)
    if ( g[i-1]+1 != g[i])
      abort ();
}

int main(int argc, char *argv[])
{
  u32 a = 0;
  vector<int> vi;
  vi.push_back(0);
  vector<int> ve;
  ve.push_back(5);
  vector<int> v7;

  auto run = [&](int& i) {
      v7.push_back(i);
      f(a++);
  };

  for_each(vi.begin(), vi.end(), [&](int& xi) {
           f(a++);
           for_each(ve.begin(), ve.end(), run);
           f(a++);
           for_each(ve.begin(), ve.end(), run);
           });
}


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