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

            Bug ID: 125282
           Summary: Referencing a structured-binding-introduced pack in
                    RHS of said binding ICEs the compiler
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: arsen at gcc dot gnu.org
  Target Milestone: ---

With -std=c++26, the following:

  template <typename = int>
  void
  f ()
  {
    auto [...x] = g (x...);
  }

  int
  main ()
  {
    f ();
  }

... produces:

  <stdin>: In instantiation of ‘void f() [with F = int]’:
  <stdin>:12:7:   required from here
  <stdin>:6:21: internal compiler error: in tsubst_pack_expansion, at
cp/pt.cc:14253

I don't have too much time to debug right now, so I'll leave a backtrace and a
dump of some of the referenced trees below:

(gdb) bt
#0  fancy_abort (file=0x555558cc45b8
"/var/tmp/portage/sys-devel/gcc-16.1.0/work/gcc-16.1.0/gcc/cp/pt.cc",
line=14253, 
    function=0x555558c11f3d "tsubst_pack_expansion") at
/usr/src/debug/sys-devel/gcc-16.1.0/gcc-16.1.0/gcc/diagnostics/context.cc:1780
#1  0x00005555560b9411 in tsubst_pack_expansion (t=<optimized out>,
args=<optimized out>, complain=3, in_decl=0x7ffff6a10b28)
    at /usr/src/debug/sys-devel/gcc-16.1.0/gcc-16.1.0/gcc/cp/pt.cc:14253
#2  0x0000555558145482 in tsubst_call_args (t=0x7ffff6bc4888,
args=0x7ffff6bc0440, complain=3, in_decl=0x7ffff6a10b28, call_args=...)
    at /usr/src/debug/sys-devel/gcc-16.1.0/gcc-16.1.0/gcc/cp/pt.cc:21339
#3  0x0000555557ed4dba in tsubst_expr (t=0x7ffff6bc4888, args=0x7ffff6bc0440,
complain=<optimized out>, in_decl=0x7ffff6a10b28)
    at /usr/src/debug/sys-devel/gcc-16.1.0/gcc-16.1.0/gcc/cp/pt.cc:22226
#4  0x000055555818de81 in tsubst_init (init=<optimized out>,
decl=0x7ffff6bc22f8, args=<optimized out>, complain=3, 
    in_decl=<optimized out>) at
/usr/src/debug/sys-devel/gcc-16.1.0/gcc-16.1.0/gcc/cp/pt.cc:18407
#5  0x000055555839497f in tsubst_stmt (t=<optimized out>,
args=args@entry=0x7ffff6bc0440, complain=complain@entry=3, 
    in_decl=in_decl@entry=0x7ffff6a10b28) at
/usr/src/debug/sys-devel/gcc-16.1.0/gcc-16.1.0/gcc/cp/pt.cc:19780
#6  0x0000555558394407 in tsubst_stmt (t=0x7ffff6a2b0c0, args=0x7ffff6bc0440,
complain=3, in_decl=0x7ffff6a10b28)
    at /usr/src/debug/sys-devel/gcc-16.1.0/gcc-16.1.0/gcc/tree.h:3781
#7  0x000055555818b1e1 in instantiate_body (pattern=<optimized out>,
args=args@entry=0x7ffff6bc0440, d=d@entry=0x7ffff6bb0700, 
    nested_p=false) at
/usr/src/debug/sys-devel/gcc-16.1.0/gcc-16.1.0/gcc/cp/pt.cc:28686
#8  0x0000555558187639 in instantiate_decl(tree_node*, bool, bool) [clone
.constprop.0] (d=0x7ffff6bb0700, expl_inst_class_mem_p=false, 
    defer_ok=false) at
/usr/src/debug/sys-devel/gcc-16.1.0/gcc-16.1.0/gcc/cp/pt.cc:28979
#9  0x0000555557a18033 in instantiate_pending_templates (retries=<optimized
out>)
    at /usr/src/debug/sys-devel/gcc-16.1.0/gcc-16.1.0/gcc/cp/pt.cc:29054
#10 0x0000555557a0ca74 in c_parse_final_cleanups () at
/usr/src/debug/sys-devel/gcc-16.1.0/gcc-16.1.0/gcc/cp/decl2.cc:5887
#11 0x00005555585e7883 in c_common_parse_file () at
/usr/src/debug/sys-devel/gcc-16.1.0/gcc-16.1.0/gcc/c-family/c-opts.cc:1448
#12 0x00005555585c9beb in compile_file () at
/usr/src/debug/sys-devel/gcc-16.1.0/gcc-16.1.0/gcc/toplev.cc:455
#13 0x00005555585694c1 in do_compile () at
/usr/src/debug/sys-devel/gcc-16.1.0/gcc-16.1.0/gcc/toplev.cc:2229
#14 toplev::main (this=this@entry=0x7fffffffc976, argc=<optimized out>,
argv=<optimized out>)
    at /usr/src/debug/sys-devel/gcc-16.1.0/gcc-16.1.0/gcc/toplev.cc:2393
#15 0x0000555558567dad in main (argc=<optimized out>, argv=<optimized out>)
    at /usr/src/debug/sys-devel/gcc-16.1.0/gcc-16.1.0/gcc/main.cc:39
(gdb) call debug_tree ((tree)0x7ffff6bc4888)
 <call_expr 0x7ffff6bc4888 tree_0
    fn <identifier_node 0x7ffff6bc5880 g
        normal local bindings <(nil)>>
    arg:0 <expr_pack_expansion 0x7ffff6a2b150
        type <type_pack_expansion 0x7ffff6bab5e8 type <decltype_type
0x7ffff6bab540>
            type_0 type_6 VOID
            align:8 warn_if_not_align:0 symtab:0 alias-set -1
structural-equality pattern <decltype_type 0x7ffff6bab540>>
        tree_0
        arg:0 <view_convert_expr 0x7ffff6bc0400 type <type_pack_expansion
0x7ffff6bab5e8>
            public arg:0 <var_decl 0x7ffff6bc2260 x>
            <stdin>:5:22 start: <stdin>:5:22 finish: <stdin>:5:22>
        arg:1 <tree_list 0x7ffff6ba4e38 value <var_decl 0x7ffff6bc2260 x>>>
    <stdin>:5:21 start: <stdin>:5:19 finish: <stdin>:5:26>
(gdb) call debug_tree ((tree) 0x7ffff6bc0440)
 <tree_vec 0x7ffff6bc0440 length:1
    elt:0 <integer_type 0x7ffff6a235e8 int public type_6 SI
        size <integer_cst 0x7ffff6a1b510 constant 32>
        unit-size <integer_cst 0x7ffff6a1b528 constant 4>
        align:32 warn_if_not_align:0 symtab:0 alias-set -1 canonical-type
0x7ffff6a235e8 precision:32 min <integer_cst 0x7ffff6a1b4c8 -2147483648> max
<integer_cst 0x7ffff6a1b4e0 2147483647>
        pointer_to_this <pointer_type 0x7ffff6a2ab28>>>
(gdb) call debug_tree ((tree) 0x7ffff6a10b28)
 <template_decl 0x7ffff6a10b28 f
    type <function_type 0x7ffff6a341f8
        type <void_type 0x7ffff6a23f18 void type_6 VOID
            align:8 warn_if_not_align:0 symtab:0 alias-set -1 canonical-type
0x7ffff6a23f18
            pointer_to_this <pointer_type 0x7ffff6a2a000>>
        QI
        size <integer_cst 0x7ffff6a1b3c0 constant 8>
        unit-size <integer_cst 0x7ffff6a1b3d8 constant 1>
        align:8 warn_if_not_align:0 symtab:0 alias-set -1 canonical-type
0x7ffff6a341f8
        arg-types <tree_list 0x7ffff6a16cd0 value <void_type 0x7ffff6a23f18
void>>
        pointer_to_this <pointer_type 0x7ffff6bab930>>
    VOID <stdin>:3:3
    align:1 warn_if_not_align:0 context <translation_unit_decl 0x7ffff6a21000
<stdin>>
    result <function_decl 0x7ffff6bb0500 f type <function_type 0x7ffff6a341f8>
        public static external QI <stdin>:3:3 align:8 warn_if_not_align:0
context <translation_unit_decl 0x7ffff6a21000 <stdin>> initial <block
0x7ffff6a0e340>
        result <result_decl 0x7ffff6a21080 D.2673 type <void_type
0x7ffff6a23f18 void>
            ignored VOID <stdin>:2:3
            align:8 warn_if_not_align:0 context <function_decl 0x7ffff6bb0500
f>>
        full-name "void f()"
        template-info <template_info 0x7ffff6ba4d48 template <template_decl
0x7ffff6a10b28 f>
            args <tree_vec 0x7ffff6bc0300 length:1 elt:0 <template_type_parm
0x7ffff6babdc8>>>
        use_template=0
        struct-function 0x7ffff7fb81a0>
    parms <tree_list 0x7ffff6ba4d20 purpose <integer_cst 0x7ffff6a1b3d8 1>
        value <tree_vec 0x7ffff6bc02e0 type <template_decl 0x7ffff6a10b28 f>
            length:1
            elt:0 <tree_list 0x7ffff6ba4cf8 purpose <integer_type
0x7ffff6a235e8 int> value <type_decl 0x7ffff6bad3c0 D.2671>>>>
    full-name "template<class> void f()" chain <function_decl 0x7ffff6baaa00
__cxa_call_terminate>>

Reply via email to