http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49651
--- Comment #6 from Richard Guenther <rguenth at gcc dot gnu.org> 2011-07-12 15:19:48 UTC --- Shorter testcase that also terminates when successful: #include <vector> #include <algorithm> extern "C" void abort (void); typedef unsigned int u32; using namespace std; vector<u32> g; void f(u32 a, 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[]) { int cnt = 256; u32 a = 0; vector<int> vi; vi.push_back(0); vi.push_back(1); vi.push_back(2); vi.push_back(3); vi.push_back(4); vector<int> vo; vo.push_back(5); vo.push_back(5); vector<int> ve; ve.push_back(5); vector<int> v3; vector<int> v4; vector<int> v5; vector<int> v6; vector<int> v7; f(32, a++); f(32, a++); auto run = [&](int& i) { // inside this lambda &a is not the same as the &a in the first line v3.push_back(i); v4.push_back(i); v5.push_back(i); v6.push_back(i); v7.push_back(i); f(32, a++); v3.push_back(i); v4.push_back(i); v5.push_back(i); v6.push_back(i); v7.push_back(i); f(32, a++); for_each(ve.begin(), ve.end(), [&](int& xi) { v7.push_back(xi); f(32, a++); }); f(32, a++); }; f(32, a++); while(--cnt) { for_each(vi.begin(), vi.end(), [&](int& xi) { f(32, a++); for_each(vo.begin(), vo.end(), run); f(32, a++); for_each(ve.begin(), ve.end(), run); f(32, a++); }); } }