===================================================================
@@ -7007,6 +7007,13 @@ cxx_eval_array_reference (const constexpr_call *ca
*non_constant_p = true;
return t;
}
+ else if (tree_int_cst_lt (index, integer_zero_node))
+ {
+ if (!allow_non_constant)
+ error ("negative array subscript");
+ *non_constant_p = true;
+ return t;
+ }
i = tree_low_cst (index, 0);
if (TREE_CODE (ary) == CONSTRUCTOR)
return (*CONSTRUCTOR_ELTS (ary))[i].value;
===================================================================
@@ -0,0 +1,9 @@
+// PR c++/56582
+// { dg-do compile { target c++11 } }
+
+// Reliable ICE
+constexpr int n[3] = {};
+constexpr int k = n[-1]; // { dg-error "negative" }
+
+// Some random byte
+constexpr char c = "foo"[-1000]; // { dg-error "negative" }