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

--- Comment #6 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
(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.

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?

Reply via email to