re PR c++/68087 (ICE with constexpr in array with negative index)

/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
This commit is contained in:
Markus Trippelsdorf 2015-11-25 16:40:16 +00:00 committed by Paolo Carlini
parent 8e2d104ba2
commit c2127564ef
4 changed files with 21 additions and 2 deletions

View 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> 2015-11-24 Ilya Verbin <ilya.verbin@intel.com>
* parser.c (cp_parser_oacc_declare): Replace "ifdef ENABLE_OFFLOADING" * parser.c (cp_parser_oacc_declare): Replace "ifdef ENABLE_OFFLOADING"

View File

@ -1799,8 +1799,8 @@ cxx_eval_array_reference (const constexpr_ctx *ctx, tree t,
gcc_unreachable (); gcc_unreachable ();
} }
i = tree_to_shwi (index); if (!tree_fits_shwi_p (index)
if (i < 0) || (i = tree_to_shwi (index)) < 0)
{ {
if (!ctx->quiet) if (!ctx->quiet)
error ("negative array subscript"); error ("negative array subscript");

View 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> 2015-11-25 Ilmir Usmanov <me@ilmir.us>
Cesar Philippidis <cesar@codesourcery.com> Cesar Philippidis <cesar@codesourcery.com>

View File

@ -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" }