https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68087
--- Comment #2 from Markus Trippelsdorf <trippels at gcc dot gnu.org> ---
Perhaps:
diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c
index ebca411..0828a90 100644
--- a/gcc/cp/constexpr.c
+++ b/gcc/cp/constexpr.c
@@ -1782,8 +1782,7 @@ cxx_eval_array_reference (const constexpr_ctx *ctx, tree
t,
gcc_unreachable ();
}
- i = tree_to_shwi (index);
- if (i < 0)
+ if (!tree_fits_shwi_p (index) || tree_to_shwi (index) < 0)
{
if (!ctx->quiet)
error ("negative array subscript");
@@ -1792,6 +1791,7 @@ cxx_eval_array_reference (const constexpr_ctx *ctx, tree
t,
}
bool found;
+ i = tree_to_shwi (index);
if (TREE_CODE (ary) == CONSTRUCTOR)
{
HOST_WIDE_INT ix = find_array_ctor_elt (ary, index);