https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79180
Bug ID: 79180 Summary: Nested lambda-capture causes segfault for parameter pack Product: gcc Version: 6.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: markus at dreseler dot de Target Milestone: --- Created attachment 40561 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=40561&action=edit Preprocessed file The following code compiles but prints garbage and then segfaults under gcc 6.3.0 on OS X: #include <iostream> #include <string> void foo(const std::string &a) { std::cout << a << std::endl; } template <typename... Args> void bar(Args &&... args) { [&]() { [&]() { foo(args...); }(); }(); } int main() { const std::string x("Hello World!"); bar(x); } Expected result: Print "Hello World!" and exit. Compiling with `-Wextra -Wall` gives this warning: param.cpp: In function 'int main()': param.cpp:11:11: warning: 'args#0' is used uninitialized in this function [-Wuninitialized] foo(args...); ^~~ param.cpp:16:5: note: 'args#0' was declared here int main() { ^~~~ Clang and VC++ do not have any issues here. People at StackOverflow seem to agree that this is valid code and appears to be a bug in GCC: http://stackoverflow.com/questions/41769851/gcc-causes-segfault-for-lambda-captured-parameter-pack Additional information: [:~/tmp] 1 $ g++-6 param.cpp && ./a.out # Garbage here Segmentation fault: 11 [:~/tmp] 139 $ g++-6 -v Using built-in specs. COLLECT_GCC=g++-6 COLLECT_LTO_WRAPPER=/usr/local/Cellar/gcc/6.3.0_1/libexec/gcc/x86_64-apple-darwin16.3.0/6.3.0/lto-wrapper Target: x86_64-apple-darwin16.3.0 Configured with: ../configure --build=x86_64-apple-darwin16.3.0 --prefix=/usr/local/Cellar/gcc/6.3.0_1 --libdir=/usr/local/Cellar/gcc/6.3.0_1/lib/gcc/6 --enable-languages=c,c++,objc,obj-c++,fortran --program-suffix=-6 --with-gmp=/usr/local/opt/gmp --with-mpfr=/usr/local/opt/mpfr --with-mpc=/usr/local/opt/libmpc --with-isl=/usr/local/opt/isl --with-system-zlib --enable-libstdcxx-time=yes --enable-stage1-checking --enable-checking=release --enable-lto --with-build-config=bootstrap-debug --disable-werror --with-pkgversion='Homebrew GCC 6.3.0_1' --with-bugurl=https://github.com/Homebrew/homebrew-core/issues --enable-plugin --disable-nls --enable-multilib Thread model: posix gcc version 6.3.0 (Homebrew GCC 6.3.0_1) [:~/tmp] 1 $ sw_vers ProductName: Mac OS X ProductVersion: 10.12.2 BuildVersion: 16C67