2017-02-21 Jakub Jelinek <jakub@redhat.com>
+ PR c++/79655
+ * constexpr.c (cxx_eval_array_reference): Diagnose negative subscript.
+
PR c++/79639
* constexpr.c (cxx_eval_store_expression): If *valp is a PTRMEM_CST,
call cplus_expand_constant on it first.
nelts = cxx_eval_constant_expression (ctx, nelts, false, non_constant_p,
overflow_p);
VERIFY_CONSTANT (nelts);
- if (lval
- ? !tree_int_cst_le (index, nelts)
- : !tree_int_cst_lt (index, nelts))
+ if ((lval
+ ? !tree_int_cst_le (index, nelts)
+ : !tree_int_cst_lt (index, nelts))
+ || tree_int_cst_sgn (index) < 0)
{
diag_array_subscript (ctx, ary, index);
*non_constant_p = true;
2017-02-21 Jakub Jelinek <jakub@redhat.com>
+ PR c++/79655
+ * g++.dg/cpp1y/constexpr-79655.C: New test.
+
PR c++/79639
* g++.dg/cpp1y/constexpr-79639.C: New test.
--- /dev/null
+// PR c++/79655
+// { dg-do compile { target c++14 } }
+
+constexpr int
+foo (int x, int y)
+{
+ int a[6] = { 1, 2, 3, 4, 5, 6 };
+ a[x] = 0;
+ return a[y];
+}
+
+constexpr int b = foo (0, -1); // { dg-error "is outside the bounds" }
+constexpr int c = foo (0, 6); // { dg-error "is outside the bounds" }
+constexpr int d = foo (6, 0); // { dg-error "is outside the bounds" }
+constexpr int e = foo (-1, 0); // { dg-error "is outside the bounds" }
+static_assert (foo (5, 5) == 0, "");
+static_assert (foo (4, 5) == 6, "");
+static_assert (foo (5, 4) == 5, "");