re PR c++/56582 (ICE on negative array index in C++11 constant expression evaluation)
authorPaolo Carlini <paolo@gcc.gnu.org>
Sat, 16 Mar 2013 10:02:11 +0000 (10:02 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Sat, 16 Mar 2013 10:02:11 +0000 (10:02 +0000)
/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

gcc/cp/ChangeLog
gcc/cp/semantics.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/constexpr-array5.C [new file with mode: 0644]

index 77f3f824c0a71fec6d8f8aad006984478c59d033..3f05f291ea603ba44a566141378a781f5a7adfc3 100644 (file)
@@ -1,3 +1,8 @@
+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>
 
        PR c++/56614
index e909b984681024d48162adf3023902a39665af77..3c76bad5a3d59ced69bbb8293fc6860da27de1ae 100644 (file)
@@ -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;
index caf8f6d1e2f72bfc455f3e672a1b08b29e9cf3c7..f9fb7f63e6aad16d5907cf9458c70fa7dbf6a095 100644 (file)
@@ -1,7 +1,12 @@
+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>
 
-       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  <ktietz@redhat.com>
 
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-array5.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-array5.C
new file mode 100644 (file)
index 0000000..4605b4b
--- /dev/null
@@ -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" }