The following code cause ICE in 4.9.2, in 5.3 cause Segmentation fault. Works ok in non-templated version. Woks ok with clang and VS. http://coliru.stacked-crooked.com/a/82069f4880198da6 #include <iostream> // std::cout #include <new> // ::operator new #include <vector> #include <tuple> #include <type_traits> using namespace std; struct Empty{}; template<class T> /* <-- Because of Template */ struct Data{ int x; float y; int properties_parcel4[10]; Empty j = [&](){ int i = 10; properties_parcel4[0] = i; return Empty(); }(); }; int main () { Data<int> k; return 0; }
Confirmed.
The workaround for all versions is use lambda that doesn't CAPTURE this, e.g. http://coliru.stacked-crooked.com/a/e223ddb156d817c1 struct Empty{}; template<class T> struct Data{ int properties_parcel4[10]; Empty j = [](auto& self){ self.properties_parcel4[0] = 10; return Empty(); }(*this); }; int main () { Data<int> k; return 0; } P.S. This maybe somehow related to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61636 - problem workarounds are same.
Author: paolo Date: Tue Oct 3 21:15:56 2017 New Revision: 253388 URL: https://gcc.gnu.org/viewcvs?rev=253388&root=gcc&view=rev Log: 2017-10-03 Paolo Carlini <paolo.carlini@oracle.com> PR c++/70343 * g++.dg/cpp0x/lambda/lambda-70343.C: New. Added: trunk/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-70343.C Modified: trunk/gcc/testsuite/ChangeLog
Fixed in trunk.