+2018-03-13 Jakub Jelinek <jakub@redhat.com>
+
+ PR c++/84808
+ * constexpr.c (find_array_ctor_elt): Don't use elt reference after
+ first potential CONSTRUCTOR_ELTS reallocation. Convert dindex to
+ sizetype. Formatting fixes.
+
2018-03-12 Jason Merrill <jason@redhat.com>
PR c++/84355 - ICE with deduction for member class template.
that the same is true of the other elements and index directly. */
if (end > 0)
{
- tree cindex = (*elts)[end-1].index;
+ tree cindex = (*elts)[end - 1].index;
if (TREE_CODE (cindex) == INTEGER_CST
- && compare_tree_int (cindex, end-1) == 0)
+ && compare_tree_int (cindex, end - 1) == 0)
{
if (i < end)
return i;
constructor_elt e;
tree lo = TREE_OPERAND (idx, 0);
tree hi = TREE_OPERAND (idx, 1);
+ tree value = elt.value;
+ dindex = fold_convert (sizetype, dindex);
if (tree_int_cst_lt (lo, dindex))
{
/* There are still some lower elts; shorten the range. */
/* Append the element we want to insert. */
++middle;
e.index = dindex;
- e.value = unshare_constructor (elt.value);
+ e.value = unshare_constructor (value);
vec_safe_insert (CONSTRUCTOR_ELTS (ary), middle, e);
}
else
e.index = hi;
else
e.index = build2 (RANGE_EXPR, sizetype, new_lo, hi);
- e.value = unshare_constructor (elt.value);
- vec_safe_insert (CONSTRUCTOR_ELTS (ary), middle+1, e);
+ e.value = unshare_constructor (value);
+ vec_safe_insert (CONSTRUCTOR_ELTS (ary), middle + 1, e);
}
}
return middle;
--- /dev/null
+// PR c++/84808
+// { dg-do compile { target c++14 } }
+
+struct A { int i; constexpr A () : i() {} };
+struct B { A a[24]; };
+
+constexpr int
+foo (int n)
+{
+ B b;
+ ++b.a[n + 20].i;
+ ++b.a[n + 18].i;
+ ++b.a[n + 16].i;
+ ++b.a[n + 14].i;
+ ++b.a[n + 12].i;
+ ++b.a[n + 10].i;
+ ++b.a[n + 8].i;
+ ++b.a[n + 6].i;
+ ++b.a[n + 4].i;
+ ++b.a[n + 2].i;
+ ++b.a[n].i;
+ return b.a[2].i + b.a[4].i + b.a[6].i + b.a[8].i + b.a[10].i
+ + b.a[12].i + b.a[14].i + b.a[16].i + b.a[18].i + b.a[20].i + b.a[22].i;
+}
+
+constexpr int i = foo (2);
+static_assert (i == 11, "");