Commit 9a54d96a by Paolo Carlini

re PR c++/56582 (ICE on negative array index in C++11 constant expression evaluation)

/cp
2013-03-16  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/56582
	* semantics.c (cxx_eval_array_reference): Check for negative index.

/testsuite
2013-03-16  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/56582
	* g++.dg/cpp0x/constexpr-array5.C: New.

From-SVN: r196701
parent 179c5970
2013-03-16 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/56582
* semantics.c (cxx_eval_array_reference): Check for negative index.
2013-03-14 Jason Merrill <jason@redhat.com> 2013-03-14 Jason Merrill <jason@redhat.com>
PR c++/56614 PR c++/56614
......
...@@ -7007,6 +7007,13 @@ cxx_eval_array_reference (const constexpr_call *call, tree t, ...@@ -7007,6 +7007,13 @@ cxx_eval_array_reference (const constexpr_call *call, tree t,
*non_constant_p = true; *non_constant_p = true;
return t; 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); i = tree_low_cst (index, 0);
if (TREE_CODE (ary) == CONSTRUCTOR) if (TREE_CODE (ary) == CONSTRUCTOR)
return (*CONSTRUCTOR_ELTS (ary))[i].value; return (*CONSTRUCTOR_ELTS (ary))[i].value;
......
2013-03-16 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/56582
* g++.dg/cpp0x/constexpr-array5.C: New.
2013-03-15 Tobias Burnus <burnus@net-b.de> 2013-03-15 Tobias Burnus <burnus@net-b.de>
PR fortran/56615 PR fortran/56615
* gfortran.dg/transfer_intrinsic_5.f90: New. * gfortran.dg/transfer_intrinsic_5.f90: New.
2013-03-15 Kai Tietz <ktietz@redhat.com> 2013-03-15 Kai Tietz <ktietz@redhat.com>
......
// 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" }
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