[Bug c++/100295] New: Internal compiler error from generic lambda capturing parameter pack and expanding it in if constexpr

davidfromonline at gmail dot com gcc-bugzilla@gcc.gnu.org
Tue Apr 27 18:44:53 GMT 2021


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

            Bug ID: 100295
           Summary: Internal compiler error from generic lambda capturing
                    parameter pack and expanding it in if constexpr
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: davidfromonline at gmail dot com
  Target Milestone: ---

The following well-formed translation unit

```
template<typename... Ts>
void f(Ts... ts) {
        auto lambda = [=](auto x) {
                if constexpr (sizeof((..., ts), x) != 0) {
                        (..., ts);
                }
        };
        lambda(0);
}

void g() {
        f(0);
}
```

causes gcc to crash with

```
<source>: In instantiation of ‘f<int>(int)::<lambda(auto:1)> [with auto:1 =
int]’:
<source>:8:8:   required from ‘void f(Ts ...) [with Ts = {int}]’
<source>:12:3:   required from here
<source>:5:31: internal compiler error: trying to capture ‘ts#0’ in
instantiation of generic lambda
    5 |                         (..., ts);
      |                               ^~
0x9c9318 add_capture(tree_node*, tree_node*, tree_node*, bool, bool)
        ../../source/gcc/cp/lambda.c:637
0x9c9391 add_default_capture(tree_node*, tree_node*, tree_node*)
        ../../source/gcc/cp/lambda.c:697
0xaa68ef tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool,
bool)
        ../../source/gcc/cp/pt.c:20834
0xaa3ea8 tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool,
bool)
        ../../source/gcc/cp/pt.c:20949
0xaaf3d7 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
        ../../source/gcc/cp/pt.c:19204
0xaae9d1 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
        ../../source/gcc/cp/pt.c:18229
0xaae9d1 gen_elem_of_pack_expansion_instantiation
        ../../source/gcc/cp/pt.c:12568
0xaae9d1 tsubst_pack_expansion(tree_node*, tree_node*, int, tree_node*)
        ../../source/gcc/cp/pt.c:13233
0xaa163f tsubst_fold_expr_pack
        ../../source/gcc/cp/pt.c:12646
0xaa163f tsubst_unary_left_fold
        ../../source/gcc/cp/pt.c:12685
0xaa163f tsubst_copy
        ../../source/gcc/cp/pt.c:17343
0xaa56f2 tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool,
bool)
        ../../source/gcc/cp/pt.c:20962
0xaaf3d7 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
        ../../source/gcc/cp/pt.c:19204
0xab11f9 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
        ../../source/gcc/cp/pt.c:18274
0xab0aa3 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
        ../../source/gcc/cp/pt.c:18595
0xab4503 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
        ../../source/gcc/cp/pt.c:18564
0xab0aa3 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
        ../../source/gcc/cp/pt.c:18595
0xab0aa3 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
        ../../source/gcc/cp/pt.c:18595
0xab8308 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
        ../../source/gcc/cp/pt.c:18229
0xab8308 instantiate_body
        ../../source/gcc/cp/pt.c:25921
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.
Compiler returned: 1
```


More information about the Gcc-bugs mailing list