Bug 83268 - [7 Regression] internal compiler error: in lambda_expr_this_capture, at cp/lambda.c:785
Summary: [7 Regression] internal compiler error: in lambda_expr_this_capture, at cp/la...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 7.2.0
: P2 normal
Target Milestone: 8.0
Assignee: Not yet assigned to anyone
URL:
Keywords: c++-lambda, ice-on-valid-code
Depends on:
Blocks: lambdas
  Show dependency treegraph
 
Reported: 2017-12-04 13:24 UTC by Zang MingJie
Modified: 2022-03-11 00:32 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work: 8.0
Known to fail: 7.5.0
Last reconfirmed: 2018-02-01 00:00:00


Attachments
testcase (133 bytes, text/x-csrc)
2017-12-04 13:26 UTC, Zang MingJie
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Zang MingJie 2017-12-04 13:24:38 UTC
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.
Comment 1 Zang MingJie 2017-12-04 13:26:51 UTC
Created attachment 42783 [details]
testcase
Comment 2 Zang MingJie 2017-12-04 13:27:32 UTC
% 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.
Comment 3 Paolo Carlini 2017-12-04 21:47:21 UTC
Works in trunk.
Comment 4 David Malcolm 2018-02-01 21:10:08 UTC
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>>>>
Comment 5 Richard Biener 2019-11-14 10:50:03 UTC
Works in GCC 8.