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

            Bug ID: 120136
           Summary: internal compiler error: tree check: accessed elt 1 of
                    'tree_vec' with -1 elts in add_to_template_args, at
                    cp/pt.cc:612
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ldalessandro at gmail dot com
  Target Milestone: ---

Created attachment 61341
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=61341&action=edit
reduced test case

Encountered via cvise while trying to reduce a difference ICE. Compile with
c++20.


```
    template <class> 
    concept car = true;

    template <auto... xs> 
    struct set {
        static auto contains(car auto x) { 
            return ((x == xs) || ...); 
        }
    };

    template <auto>
    struct foo {
        template <car auto c>
        friend bool operator==(foo, foo<c>);
    };

    template <car auto c> foo<c> foobar;

    auto a = foobar<1>;
    auto b = set<a>{};
    auto c = b.contains(a);
```

Live: https://godbolt.org/z/q1b6746vb [May 6th, 2025]

<source>: In substitution of 'template<auto [requires ::car<<placeholder>, >]
c> bool operator==(foo<1>, foo<c>) [with auto [requires ::car<<placeholder>, >]
c = <missing>]':
<source>:7:20:   required from 'static auto set<xs>::contains(auto:1) [with
auto:1 = foo<1>; auto ...xs = {foo<1>()}]'
    7 |         return ((x == xs) || ...);
      |                 ~~~^~~~~~
<source>:21:20:   required from here
   21 | auto c = b.contains(a);
      |          ~~~~~~~~~~^~~
<source>:7:20: internal compiler error: tree check: accessed elt 1 of
'tree_vec' with -1 elts in add_to_template_args, at cp/pt.cc:612
    7 |         return ((x == xs) || ...);
      |                 ~~~^~~~~~
0x293a4f5 diagnostic_context::diagnostic_impl(rich_location*,
diagnostic_metadata const*, diagnostic_option_id, char const*, __va_list_tag
(*) [1], diagnostic_t)
        ???:0
0x2951766 internal_error(char const*, ...)
        ???:0
0x9e0ef3 tree_vec_elt_check_failed(int, int, char const*, int, char const*)
        ???:0
0xd1c098 do_auto_deduction(tree_node*, tree_node*, tree_node*, int,
auto_deduction_context, tree_node*, int, tree_node*)
        ???:0
0xd5ac0f fn_type_unification(tree_node*, tree_node*, tree_node*, tree_node*
const*, unsigned int, tree_node*, unification_kind_t, int, conversion**, bool,
bool)
        ???:0
0xb114d6 build_new_op(op_location_t const&, tree_code, int, tree_node*,
tree_node*, tree_node*, tree_node*, tree_node**, int)
        ???:0
0xdbbcf2 build_x_binary_op(op_location_t const&, tree_code, tree_node*,
tree_code, tree_node*, tree_code, tree_node*, tree_node**, int)
        ???:0
0xd444e4 tsubst_pack_expansion(tree_node*, tree_node*, int, tree_node*)
        ???:0
0xd25add instantiate_decl(tree_node*, bool, bool)
        ???:0
0xbdea93 maybe_instantiate_decl(tree_node*)
        ???:0
0xbe0787 mark_used(tree_node*, int)
        ???:0
0xaf7ed3 build_new_method_call(tree_node*, tree_node*, vec<tree_node*, va_gc,
vl_embed>**, tree_node*, int, tree_node**, int)
        ???:0
0xd7c639 finish_call_expr(tree_node*, vec<tree_node*, va_gc, vl_embed>**, bool,
bool, int)
        ???:0
0xcfb063 c_parse_file()
        ???:0
0xe5db29 c_common_parse_file()
        ???:0

Reply via email to