https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86594

            Bug ID: 86594
           Summary: Crash on trying to capture 'this' in instantiation of
                    generic lambda
           Product: gcc
           Version: 9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: zhonghao at pku dot org.cn
  Target Milestone: ---

The code is as follow:

#include <tuple>

template <typename T, T... S, typename F>
constexpr void for_sequence(std::integer_sequence<T, S...>, F&& f) {
        using unpack_t = int[];
        (void)unpack_t{(static_cast<void>(f(std::integral_constant<T, S>{})),
0)..., 0};
}

template<typename Tup>
struct MyType {
        void crash() {
               
for_sequence(std::make_index_sequence<std::tuple_size<Tup>::value>{}, [&](auto
i){
                        make_crash<i>();
                });
        }

        template<int i>
        void make_crash() {}
};

int main() {
        MyType<std::tuple<int, double, double, const char*>> test;

        test.crash();
}

g++ crashes with the following messages:

crash.cpp: In instantiation of 'MyType<Tup>::crash() [with Tup =
std::tuple<int, double, double, const char*>]::<lambda(auto:1)> [with auto:1 =
std::integral_constant<long unsigned int, 0>]':
2CPPfilethattriggerthecrash.cpp:6:37:   required from 'constexpr void
for_sequence(std::integer_sequence<T, S ...>, F&&) [with T = long unsigned int;
T ...S = {0, 1, 2, 3}; F = MyType<Tup>::crash() [with Tup = std::tuple<int,
double, double, const char*>]::<lambda(auto:1)>]'
2CPPfilethattriggerthecrash.cpp:12:15:   required from 'void
MyType<Tup>::crash() [with Tup = std::tuple<int, double, double, const char*>]'
2CPPfilethattriggerthecrash.cpp:24:13:   required from here
2CPPfilethattriggerthecrash.cpp:13:4: internal compiler error: trying to
capture 'this' in instantiation of generic lambda
    make_crash<i>();
    ^~~~~~~~~~
0x90c905 add_capture(tree_node*, tree_node*, tree_node*, bool, bool)
        ../../gcc9.0/gcc/cp/lambda.c:648
0x90ca5e add_default_capture(tree_node*, tree_node*, tree_node*)
        ../../gcc9.0/gcc/cp/lambda.c:714
0x90cf01 lambda_expr_this_capture(tree_node*, bool)
        ../../gcc9.0/gcc/cp/lambda.c:819
0x90d670 maybe_resolve_dummy(tree_node*, bool)
        ../../gcc9.0/gcc/cp/lambda.c:902
0x85762a build_new_method_call_1
        ../../gcc9.0/gcc/cp/call.c:9416
0x85762a build_new_method_call(tree_node*, tree_node*, vec<tree_node*, va_gc,
vl_embed>**, tree_node*, int, tree_node**, int)
        ../../gcc9.0/gcc/cp/call.c:9531
0x9adcb8 tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool,
bool)
        ../../gcc9.0/gcc/cp/pt.c:18491
0x991329 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
        ../../gcc9.0/gcc/cp/pt.c:17431
0x99166d tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
        ../../gcc9.0/gcc/cp/pt.c:16630
0x991390 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
        ../../gcc9.0/gcc/cp/pt.c:16915
0x991390 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
        ../../gcc9.0/gcc/cp/pt.c:16915
0x991390 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
        ../../gcc9.0/gcc/cp/pt.c:16915
0x9bf24e tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
        ../../gcc9.0/gcc/cp/pt.c:16601
0x9bf24e instantiate_decl(tree_node*, bool, bool)
        ../../gcc9.0/gcc/cp/pt.c:24075
0x8e603b maybe_instantiate_decl
        ../../gcc9.0/gcc/cp/decl2.c:5173
0x8e8167 mark_used(tree_node*, int)
        ../../gcc9.0/gcc/cp/decl2.c:5323
0x854e8e build_over_call
        ../../gcc9.0/gcc/cp/call.c:8325
0x862b2a build_op_call_1
        ../../gcc9.0/gcc/cp/call.c:4602
0x862b2a build_op_call(tree_node*, vec<tree_node*, va_gc, vl_embed>**, int)
        ../../gcc9.0/gcc/cp/call.c:4631
0x9d95ad finish_call_expr(tree_node*, vec<tree_node*, va_gc, vl_embed>**, bool,
bool, int)
        ../../gcc9.0/gcc/cp/semantics.c:2553
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.

Reply via email to