Commit 95e3030c by Marek Polacek Committed by Marek Polacek

re PR c++/69496 ([C++ 14] ICE on VLA in constexpr function)

	PR c++/69496
	* constexpr.c (cxx_eval_array_reference): Evaluate the number of
	elements of the array.

	* g++.dg/ext/constexpr-vla1.C: New test.

From-SVN: r232875
parent 5128d392
2016-01-27 Marek Polacek <polacek@redhat.com>
PR c++/69496
* constexpr.c (cxx_eval_array_reference): Evaluate the number of
elements of the array.
2016-01-26 Jason Merrill <jason@redhat.com>
PR c++/68949
......
......@@ -1846,7 +1846,12 @@ cxx_eval_array_reference (const constexpr_ctx *ctx, tree t,
if (!found)
{
if (tree_int_cst_lt (index, array_type_nelts_top (TREE_TYPE (ary))))
tree nelts = array_type_nelts_top (TREE_TYPE (ary));
/* For VLAs, the number of elements won't be an integer constant. */
nelts = cxx_eval_constant_expression (ctx, nelts, false, non_constant_p,
overflow_p);
VERIFY_CONSTANT (nelts);
if (tree_int_cst_lt (index, nelts))
{
if (TREE_CODE (ary) == CONSTRUCTOR
&& CONSTRUCTOR_NO_IMPLICIT_ZERO (ary))
......
2016-01-27 Marek Polacek <polacek@redhat.com>
PR c++/69496
* g++.dg/ext/constexpr-vla1.C: New test.
2016-01-20 Christian Bruel <christian.bruel@st.com>
PR target/69245
......
// PR c++/69496
// { dg-do compile { target c++14 } }
constexpr int
fn_ok (int n)
{
__extension__ int a[n] = { };
int z = 0;
for (unsigned i = 0; i < sizeof (a) / sizeof (int); ++i)
z += a[i];
return z;
}
constexpr int
fn_not_ok (int n)
{
__extension__ int a[n] = { };
int z = 0;
for (unsigned i = 0; i < sizeof (a); ++i)
z += a[i];
return z;
}
constexpr int n1 = fn_ok (3);
constexpr int n2 = fn_not_ok (3); // { dg-error "array subscript out of bound" }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment