* constexpr.c (cxx_eval_pointer_plus_expression): Check constancy
of nelts.
* cp-gimplify.c (cp_fully_fold): Only maybe_constant_value in
C++11 and up.
From-SVN: r238957
+2016-08-01 Jason Merrill <jason@redhat.com>
+
+ PR c++/72766
+ * constexpr.c (cxx_eval_pointer_plus_expression): Check constancy
+ of nelts.
+ * cp-gimplify.c (cp_fully_fold): Only maybe_constant_value in
+ C++11 and up.
+
2016-07-30 Martin Sebor <msebor@redhat.com>
PR c++/60760
tree type = TREE_TYPE (op00);
t = fold_convert_loc (loc, ssizetype, TREE_OPERAND (op00, 1));
tree nelts = array_type_nelts_top (TREE_TYPE (TREE_OPERAND (op00, 0)));
+ nelts = cxx_eval_constant_expression (ctx, nelts, false, non_constant_p,
+ overflow_p);
+ if (*non_constant_p)
+ return NULL_TREE;
/* Don't fold an out-of-bound access. */
if (!tree_int_cst_le (t, nelts))
return NULL_TREE;
return x;
/* FIXME cp_fold ought to be a superset of maybe_constant_value so we don't
have to call both. */
- x = maybe_constant_value (x);
+ if (cxx_dialect >= cxx11)
+ x = maybe_constant_value (x);
return cp_fold (x);
}
--- /dev/null
+// PR c++/72766
+// { dg-options "-Wno-vla" }
+
+long fn1() {
+ const int a = fn1();
+ int b[a];
+ int c = *(&b[0] + sizeof(0));
+}