re PR c++/68087 (ICE with constexpr in array with negative index)
authorMarkus Trippelsdorf <markus@trippelsdorf.de>
Wed, 25 Nov 2015 16:40:16 +0000 (16:40 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Wed, 25 Nov 2015 16:40:16 +0000 (16:40 +0000)
/cp
2015-11-25  Markus Trippelsdorf  <markus@trippelsdorf.de>
    Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/68087
* constexpr.c (cxx_eval_array_reference): Use tree_fits_shwi_p before
tree_to_shwi to avoid ICEs.

/testsuite
2015-11-25  Markus Trippelsdorf  <markus@trippelsdorf.de>
    Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/68087
* g++.dg/cpp0x/constexpr-array13.C: New.

Co-Authored-By: Paolo Carlini <paolo.carlini@oracle.com>
From-SVN: r230886

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

index a4aa01e3b2ac43830a6ea226f022751d03672afa..c94ae5f1cc460fa243e387e6f1eba6e129bc8957 100644 (file)
@@ -1,3 +1,10 @@
+2015-11-25  Markus Trippelsdorf  <markus@trippelsdorf.de>
+           Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/68087
+       * constexpr.c (cxx_eval_array_reference): Use tree_fits_shwi_p before
+       tree_to_shwi to avoid ICEs.
+
 2015-11-24  Ilya Verbin  <ilya.verbin@intel.com>
 
        * parser.c (cp_parser_oacc_declare): Replace "ifdef ENABLE_OFFLOADING"
index 459173dec07113ae74788ec33bf92e9741a10ec8..42e99021f11fc57d0c52c087876e4b8b30070075 100644 (file)
@@ -1799,8 +1799,8 @@ cxx_eval_array_reference (const constexpr_ctx *ctx, tree t,
       gcc_unreachable ();
     }
 
-  i = tree_to_shwi (index);
-  if (i < 0)
+  if (!tree_fits_shwi_p (index)
+      || (i = tree_to_shwi (index)) < 0)
     {
       if (!ctx->quiet)
        error ("negative array subscript");
index 58bd40ab40432adc4ef75ca1aea3fc3340c21ddc..e0b16f592e79a7efa2f3c03df31b40f5eee093af 100644 (file)
@@ -1,3 +1,9 @@
+2015-11-25  Markus Trippelsdorf  <markus@trippelsdorf.de>
+           Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/68087
+       * g++.dg/cpp0x/constexpr-array13.C: New.
+
 2015-11-25  Ilmir Usmanov <me@ilmir.us>
            Cesar Philippidis  <cesar@codesourcery.com>
 
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-array13.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-array13.C
new file mode 100644 (file)
index 0000000..13ab5a7
--- /dev/null
@@ -0,0 +1,6 @@
+// PR c++/68087
+// { dg-do compile { target c++11 } }
+
+constexpr char c[] = "hello";
+constexpr const char *p = c;
+constexpr char ch = *(p-1);  // { dg-error "negative array subscript" }