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

            Bug ID: 122204
           Summary: ICE when deducing a concept-constrained constant
                    template parameter
           Product: gcc
           Version: 12.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: sebastian.redl at getdesigned dot at
  Target Milestone: ---

This is the most reduced test case I could find, compiled with -std=c++20:

---
template <int param>
struct A {};

template <typename T>
struct IsA {
  static constexpr bool value = true;
};

template <typename T>
concept Ac = IsA<T>::value;

template <Ac auto dim>
struct V {};

template <typename T>
struct IsV {};
template <Ac auto dim>
struct IsV<V<dim>> {};

template <int i>
struct B {
  template <Ac auto dim>
  void f(V<dim>) const;
};

void crashing_function() { B<0>{}.f(V<A<0>{}>{}); }
---

If I remove the (unused) IsV or its specialization, the ICE does not occur. If
I make the concept Ac directly true instead of indirecting it, the ICE does not
occur.

This bug can be reproduced starting with GCC 12.4; 12.3 does not exhibit it and
produces code. All versions up to and including current trunk (according to
godbolt) exhibit the bug.

Output of 12.4 on godbolt:

---
<source>: In substitution of 'template<auto [requires ::Ac<<placeholder>, >]
dim> void B<0>::f(V<dim>) const [with auto [requires ::Ac<<placeholder>, >] dim
= <missing>]':
<source>:27:36:   required from here
<source>:27:36: internal compiler error: in tsubst, at cp/pt.cc:15914
   27 | void crashing_function() { B<0>{}.f(V<A<0>{}>{}); }
      |                            ~~~~~~~~^~~~~~~~~~~~~
0x1bd4b0c internal_error(char const*, ...)
        ???:0
0x6f5da5 fancy_abort(char const*, int, char const*)
        ???:0
0x751d58 constraints_satisfied_p(tree_node*, tree_node*)
        ???:0
0x87569b do_auto_deduction(tree_node*, tree_node*, tree_node*, int,
auto_deduction_context, tree_node*, int, tree_node*)
        ???:0
0x899d07 fn_type_unification(tree_node*, tree_node*, tree_node*, tree_node*
const*, unsigned int, tree_node*, unification_kind_t, int, conversion**, bool,
bool)
        ???:0
0x71ac57 build_new_method_call(tree_node*, tree_node*, vec<tree_node*, va_gc,
vl_embed>**, tree_node*, int, tree_node**, int)
        ???:0
0x862784 c_parse_file()
        ???:0
0x9455b5 c_common_parse_file()
        ???:0
---

Output of 15.2 (the newest godbolt at this time) is identical, except for an
additional stack frame for diagnostic_context::diagnostic_impl.

Output of trunk, which is built with assertions:

---
<source>: In substitution of 'template<auto [requires ::Ac<<placeholder>, >]
dim> void B<0>::f(V<dim>) const [with auto [requires ::Ac<<placeholder>, >] dim
= <missing>]':
required from here
<source>:27:36:   
   27 | void crashing_function() { B<0>{}.f(V<A<0>{}>{}); }
      |                            ~~~~~~~~^~~~~~~~~~~~~
<source>:27:36: internal compiler error: tree check: accessed elt 1 of
'tree_vec' with -1 elts in add_to_template_args, at cp/pt.cc:612
0x28d4a08 diagnostics::context::diagnostic_impl(rich_location*,
diagnostics::metadata const*, diagnostics::option_id, char const*,
__va_list_tag (*) [1], diagnostics::kind)
        ???:0
0x28c993b internal_error(char const*, ...)
        ???:0
0xa0dee1 tree_vec_elt_check_failed(int, int, char const*, int, char const*)
        ???:0
0xd63fa8 do_auto_deduction(tree_node*, tree_node*, tree_node*, int,
auto_deduction_context, tree_node*, int, tree_node*)
        ???:0
0xda0591 fn_type_unification(tree_node*, tree_node*, tree_node*, tree_node*
const*, unsigned int, tree_node*, unification_kind_t, int, conversion**, bool,
bool)
        ???:0
0xb24e1b build_new_method_call(tree_node*, tree_node*, vec<tree_node*, va_gc,
vl_embed>**, tree_node*, int, tree_node**, int)
        ???:0
0xdc2e09 finish_call_expr(tree_node*, vec<tree_node*, va_gc, vl_embed>**, bool,
bool, int)
        ???:0
0xd3bc93 c_parse_file()
        ???:0
0xeac399 c_common_parse_file()
        ???:0
---

Output of --version for this trunk:
g++
(Compiler-Explorer-Build-gcc-491cae7d301c6e798b2cd90fffe090e1c895f0e4-binutils-2.44)
16.0.0 20251008 (experimental)

Reply via email to