The following C++14 file produces an internal compiler error. #include <functional> int t(std::function<void(int&&)>&&); struct X { int f(); int operator()() { return t([&](auto) -> void { [x = f()]{}(); }); } }; % g++ -std=c++14 -c bug.cpp bug.cpp: In instantiation of ‘struct X::operator()()::<lambda(auto:1)> [with auto:1 = int]::<lambda()>’: bug.cpp:9:15: required from ‘X::operator()()::<lambda(auto:1)> [with auto:1 = int]’ /usr/include/c++/7/bits/std_function.h:316:37: required from ‘static void std::_Function_handler<void(_ArgTypes ...), _Functor>::_M_invoke(const std::_Any_data&, _ArgTypes&& ...) [with _Functor = X::operator()()::<lambda(auto:1)>; _ArgTypes = {int&&}]’ /usr/include/c++/7/bits/std_function.h:694:19: required from ‘std::function<_Res(_ArgTypes ...)>::function(_Functor) [with _Functor = X::operator()()::<lambda(auto:1)>; <template-parameter-2-2> = void; <template-parameter-2-3> = void; _Res = void; _ArgTypes = {int&&}]’ bug.cpp:10:4: required from here bug.cpp:9:10: internal compiler error: in lambda_expr_this_capture, at cp/lambda.c:785 [x = f()]{}(); ~^~ Please submit a full bug report, with preprocessed source if appropriate. See <file:///usr/share/doc/gcc-7/README.Bugs> for instructions.
Created attachment 42783 [details] testcase
% gcc --version gcc (Debian 7.2.0-16) 7.2.0 Copyright (C) 2017 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Works in trunk.
Confirmed that this ICEs gcc 7 (but trunk and gcc 6 don't ICE). ICE is here in lambda_expr_this_capture: 784 gcc_assert (TYPE_MAIN_VARIANT (TREE_TYPE (current_class_ref)) (gdb) call debug_tree (cfun->language->x_current_class_ref) <indirect_ref 0x7ffff0109e80 type <record_type 0x7ffff0245888 __lambda0 readonly type_5 type_6 DI size <integer_cst 0x7ffff18aceb8 constant 64> unit size <integer_cst 0x7ffff18aced0 constant 8> align 64 symtab 0 alias set -1 canonical type 0x7ffff0245888 fields <field_decl 0x7ffff0248558 __this type <pointer_type 0x7ffff0245a80> used unsigned nonlocal decl_7 DI file /tmp/test.C line 9 col 11 size <integer_cst 0x7ffff18aceb8 64> unit size <integer_cst 0x7ffff18aced0 8> align 64 offset_align 128 offset <integer_cst 0x7ffff18acee8 constant 0> bit offset <integer_cst 0x7ffff18acf30 constant 0> context <record_type 0x7ffff0245d20 __lambda0> chain <type_decl 0x7ffff0248428 __lambda0>> context <function_decl 0x7ffff0249200 operator()> full-name "const struct X::operator()()::<lambda(auto:1)>" X() X(constX&) this=(X&) n_parents=0 use_template=0 interface-unknown pointer_to_this <pointer_type 0x7ffff0245bd0> reference_to_this <reference_type 0x7ffff02979d8>> readonly arg 0 <nop_expr 0x7ffff0109e60 type <pointer_type 0x7ffff0245bd0 type <record_type 0x7ffff0245888 __lambda0> unsigned type_6 DI size <integer_cst 0x7ffff18aceb8 64> unit size <integer_cst 0x7ffff18aced0 8> align 64 symtab 0 alias set -1 canonical type 0x7ffff0245bd0> readonly arg 0 <parm_decl 0x7ffff0266c00 __closure type <pointer_type 0x7ffff024b0a8> readonly used unsigned DI file /tmp/test.C line 8 col 25 size <integer_cst 0x7ffff18aceb8 64> unit size <integer_cst 0x7ffff18aced0 8> align 64 context <function_decl 0x7ffff0267e00 operator()> arg-type <pointer_type 0x7ffff024b0a8> chain <parm_decl 0x7ffff0266c80 D.30370>>>>
Works in GCC 8.