From: Paolo Carlini Date: Sat, 16 Mar 2013 10:02:11 +0000 (+0000) Subject: re PR c++/56582 (ICE on negative array index in C++11 constant expression evaluation) X-Git-Tag: releases/gcc-4.9.0~7050 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=9a54d96aabdc4501573aa0cd2f5201a206963f69;p=thirdparty%2Fgcc.git re PR c++/56582 (ICE on negative array index in C++11 constant expression evaluation) /cp 2013-03-16 Paolo Carlini PR c++/56582 * semantics.c (cxx_eval_array_reference): Check for negative index. /testsuite 2013-03-16 Paolo Carlini PR c++/56582 * g++.dg/cpp0x/constexpr-array5.C: New. From-SVN: r196701 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 77f3f824c0a7..3f05f291ea60 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2013-03-16 Paolo Carlini + + PR c++/56582 + * semantics.c (cxx_eval_array_reference): Check for negative index. + 2013-03-14 Jason Merrill PR c++/56614 diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index e909b9846810..3c76bad5a3d5 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -7007,6 +7007,13 @@ cxx_eval_array_reference (const constexpr_call *call, tree t, *non_constant_p = true; 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); if (TREE_CODE (ary) == CONSTRUCTOR) return (*CONSTRUCTOR_ELTS (ary))[i].value; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index caf8f6d1e2f7..f9fb7f63e6aa 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,7 +1,12 @@ +2013-03-16 Paolo Carlini + + PR c++/56582 + * g++.dg/cpp0x/constexpr-array5.C: New. + 2013-03-15 Tobias Burnus - PR fortran/56615 - * gfortran.dg/transfer_intrinsic_5.f90: New. + PR fortran/56615 + * gfortran.dg/transfer_intrinsic_5.f90: New. 2013-03-15 Kai Tietz diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-array5.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-array5.C new file mode 100644 index 000000000000..4605b4be902b --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-array5.C @@ -0,0 +1,9 @@ +// 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" }