http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53619
Bug #: 53619 Summary: [c++11, regression] wrong capture of "this" in lambda in case of polymorphism Classification: Unclassified Product: gcc Version: 4.8.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassig...@gcc.gnu.org ReportedBy: vincenzo.innoce...@cern.ch in this example "x" is wrongly captured ./a.out in foo 1 in lambda 4203472 Segmentation fault (core dumped) removing the inheritance from B works "as expected" It starts at the same time I had to capture "this" explicitly… (sorry, only now had the time to debug it fully and reduce it some how) #include<iostream> struct CA { const int x; constexpr CA(int i) : x(i){} }; struct B { virtual ~B(){} }; struct A : public B, private CA { A(CA const c) : CA(c){} int foo(int *, int); }; int A::foo(int * h, int l) { std::cout << "in foo " << x << std::endl; int a=0; auto k = [&a, &h ,this](int i) { std::cout << "in lambda " << x << std::endl; a+=h[x+i]; }; for (int i=0; i!=l; ++i) k(i); return a; } int main(int l, char **) { CA ca(1); A a(ca); int h[l+2]; h[0]=l; std::cout << a.foo(h,l) << std::endl; }