http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52739
Bug #: 52739 Summary: [c++0x] Segfault because of nested lambda member capture inside member template Classification: Unclassified Product: gcc Version: 4.6.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassig...@gcc.gnu.org ReportedBy: bruno-...@defraine.net In the following specific combination of a class template, a member template, and two nested lambdas, where the outer lambda captures `this' and the inner lambda captures a member of `this', I can trigger a gcc segmentation fault. test.cpp contains: template<int n> class Test { int i; public: template<typename Func> void foo(const Func& f); }; template<int n> template<typename Func> void Test<n>::foo(const Func& f) { auto lam1 = [this,&f]() { auto lam2 = [&i,&f]() { f(i); }; }; } void bar(Test<1>& t) { t.foo([](int i) { }); } The compilation: $ g++ -Wall -O2 -std=c++0x -c test.cpp test.cpp: In lambda function: test.cpp:12:17: internal compiler error: Segmentation fault Please submit a full bug report, with preprocessed source if appropriate. See <http://gcc.gnu.org/bugs.html> for instructions. The segmentation fault is always reproducible with gcc 4.6.2 on two platforms: $ g++ -v Using built-in specs. COLLECT_GCC=g++ COLLECT_LTO_WRAPPER=/opt/gcc-4.6.2/libexec/gcc/x86_64-unknown-linux-gnu/4.6.2/lto-wrapper Target: x86_64-unknown-linux-gnu Configured with: ../configure --prefix=/opt/gcc-4.6.2 --enable-languages=c,c++,fortran --disable-multilib Thread model: posix gcc version 4.6.2 (GCC) $ g++-fsf-4.6 -v Using built-in specs. COLLECT_GCC=g++-fsf-4.6 COLLECT_LTO_WRAPPER=/sw/lib/gcc4.6/libexec/gcc/x86_64-apple-darwin11.2.0/4.6.2/lto-wrapper Target: x86_64-apple-darwin11.2.0 Configured with: ../gcc-4.6.2/configure --prefix=/sw --prefix=/sw/lib/gcc4.6 --mandir=/sw/share/man --infodir=/sw/lib/gcc4.6/info --enable-languages=c,c++,fortran,lto,objc,obj-c++,java --with-gmp=/sw --with-libiconv-prefix=/sw --with-ppl=/sw --with-cloog=/sw --with-mpc=/sw --with-system-zlib --x-includes=/usr/X11R6/include --x-libraries=/usr/X11R6/lib --program-suffix=-fsf-4.6 --enable-cloog-backend=isl Thread model: posix gcc version 4.6.2 (GCC) I haven't tested this yet using gcc 4.6.3 nor gcc 4.7. My apologies if this has been already fixed.