https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113834
--- Comment #7 from Marek Polacek <mpolacek at gcc dot gnu.org> --- (In reply to Jakub Jelinek from comment #6) > (In reply to Marek Polacek from comment #5) > > To fix the ICE we could do: > > > > --- a/gcc/cp/semantics.cc > > +++ b/gcc/cp/semantics.cc > > @@ -4644,7 +4644,9 @@ static tree > > finish_type_pack_element (tree idx, tree types, tsubst_flags_t complain) > > { > > idx = maybe_constant_value (idx); > > - if (TREE_CODE (idx) != INTEGER_CST || !INTEGRAL_TYPE_P (TREE_TYPE (idx))) > > + if (TREE_CODE (idx) != INTEGER_CST > > + || !INTEGRAL_TYPE_P (TREE_TYPE (idx)) > > + || !tree_fits_shwi_p (idx)) > > { > > if (complain & tf_error) > > error ("%<__type_pack_element%> index is not an integral constant"); > > But then the diagnostics is confusing. There's a lot of places where we do exactly that: handle_assume_aligned_attribute, ... > Perhaps use tree_int_cst_sgn (idx) < 0 instead of tree_to_shwi + val < 0, > wi::to_widest (idx) >= TREE_VEC_LENGTH (types) for out of range and > only use tree_to_shwi after those checks? That sounds good too though, I can do that instead.