Bug 82474 - [8 Regression] ICE: trying to capture ‘list’ in instantiation of generic lambda
Summary: [8 Regression] ICE: trying to capture ‘list’ in instantiation of generic lambda
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 8.0
: P3 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-10-08 08:54 UTC by Markus Trippelsdorf
Modified: 2022-03-11 00:32 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2017-10-08 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Markus Trippelsdorf 2017-10-08 08:54:39 UTC
% cat laws.functor.ii
struct A;
struct B {
  template <typename X> void operator()(X) const;
};
template <typename> B make;
template <typename, typename = A> struct TestMonad {
  template <typename Xs, typename XXs> TestMonad(Xs, XXs);
};
template <typename S> struct TestMonad<S> : TestMonad<S, int> {
  template <typename Xs, typename XXs>
  TestMonad(Xs, XXs) : TestMonad<S, int>{0, 0} {
    constexpr auto list = make<S>;
    [=](auto x) { list(x); }(0);
  }
};
int main() { TestMonad<int>{0, 0}; }

 % g++ -c laws.functor.ii
laws.functor.ii: In instantiation of ‘TestMonad<S>::TestMonad(Xs, XXs) [with Xs = int; XXs = int; S = int]::<lambda(auto:1)> [with auto:1 = int]’:
laws.functor.ii:13:29:   required from ‘TestMonad<S>::TestMonad(Xs, XXs) [with Xs = int; XXs = int; S = int]’
laws.functor.ii:16:33:   required from here
laws.functor.ii:13:23: internal compiler error: trying to capture ‘list’ in instantiation of generic lambda
     [=](auto x) { list(x); }(0);
                   ~~~~^~~
0x10354b8b add_capture(tree_node*, tree_node*, tree_node*, bool, bool)
        ../../gcc/gcc/cp/lambda.c:624
0x103550c7 add_default_capture(tree_node*, tree_node*, tree_node*)
        ../../gcc/gcc/cp/lambda.c:695
0x104a4957 process_outer_var_ref(tree_node*, int, bool)
        ../../gcc/gcc/cp/semantics.c:3371
0x1033bb93 mark_use
        ../../gcc/gcc/cp/expr.c:121
0x104fcf3b cp_build_addr_expr_1
        ../../gcc/gcc/cp/typeck.c:5655
0x10211787 build_this
        ../../gcc/gcc/cp/call.c:3368
0x102290b7 add_function_candidate
        ../../gcc/gcc/cp/call.c:2163
0x1022a547 add_template_candidate_real
        ../../gcc/gcc/cp/call.c:3211
0x1022af97 add_template_candidate
        ../../gcc/gcc/cp/call.c:3253
0x1022af97 add_candidates
        ../../gcc/gcc/cp/call.c:5517
0x10232137 build_op_call_1
        ../../gcc/gcc/cp/call.c:4496
0x10232137 build_op_call(tree_node*, vec<tree_node*, va_gc, vl_embed>**, int)
        ../../gcc/gcc/cp/call.c:4585
0x104a414b finish_call_expr(tree_node*, vec<tree_node*, va_gc, vl_embed>**, bool, bool, int)
        ../../gcc/gcc/cp/semantics.c:2502
0x1042cf53 tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool, bool)
        ../../gcc/gcc/cp/pt.c:17764
0x1043294b tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
        ../../gcc/gcc/cp/pt.c:16728
0x1043096b tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
        ../../gcc/gcc/cp/pt.c:15974
0x104328ff tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
        ../../gcc/gcc/cp/pt.c:16203
0x104328ff tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
        ../../gcc/gcc/cp/pt.c:16203
0x104328ff tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
        ../../gcc/gcc/cp/pt.c:16203
0x10477b93 instantiate_decl(tree_node*, bool, bool)
        ../../gcc/gcc/cp/pt.c:23262
Comment 1 Paolo Carlini 2017-10-10 16:59:25 UTC
Related to PR81299.
Comment 2 Markus Trippelsdorf 2017-10-11 04:40:35 UTC
Fixed by r253601.