PR c++/68308 - [6 Regression] ICE: tree check: expected integer_cst,

have var_decl in decompose, at tree.h:5105

gcc/
    * cp/init.c (build_new_1): Check for expression constness
    the right way.

testsuite/
    * g++.dg/init/new46.C: New test.

From-SVN: r230468
This commit is contained in:
Martin Sebor 2015-11-17 18:09:36 +00:00 committed by Martin Sebor
parent 54e484eb15
commit f091ee191c
4 changed files with 79 additions and 2 deletions

View File

@ -1,3 +1,9 @@
2015-11-17 Martin Sebor <msebor@redhat.com>
PR c++/68308
* cp/init.c (build_new_1): Check for expression constness
the right way.
2015-11-17 Sandra Loosemore <sandra@codesourcery.com>
PR target/56036

View File

@ -2715,7 +2715,7 @@ build_new_1 (vec<tree, va_gc> **placement, tree type, tree nelts,
size = size_binop (MULT_EXPR, size, fold_convert (sizetype, nelts));
if (TREE_CONSTANT (outer_nelts))
if (INTEGER_CST == TREE_CODE (outer_nelts))
{
if (tree_int_cst_lt (max_outer_nelts_tree, outer_nelts))
{
@ -3330,7 +3330,8 @@ build_new (vec<tree, va_gc> **placement, tree type, tree nelts,
non-class type and its value before converting to std::size_t is
less than zero. ... If the expression is a constant expression,
the program is ill-fomed. */
if (TREE_CONSTANT (cst_nelts) && tree_int_cst_sgn (cst_nelts) == -1)
if (INTEGER_CST == TREE_CODE (cst_nelts)
&& tree_int_cst_sgn (cst_nelts) == -1)
{
if (complain & tf_error)
error ("size of array is negative");

View File

@ -1,3 +1,8 @@
2015-11-17 Martin Sebor <msebor@redhat.com>
PR c++/68308
* g++.dg/init/new46.C: New test.
2015-11-17 Dominique d'Humieres <dominiq@lps.ens.fr>
PR fortran/65751

View File

@ -0,0 +1,65 @@
// { dg-do compile }
// { dg-options "-Wall" }
// Test for c++/68308 - [6 Regression] ICE: tree check: expected integer_cst,
// have var_decl in decompose, at tree.h:5105
typedef __typeof__ (sizeof 0) size_t;
// Not defined, only referenced in templates that aren't expected
// to be instantiated to make sure they really aren't to verify
// verify c++/68308.
template <class T> void inst_check ();
// Not instantiated (must not be diagnosed).
template <class T>
char* fn1_x () {
const size_t a = sizeof (T);
return inst_check<T>() ? new char [a] : 0;
}
// Not instantiated (must not be diagnosed).
template <size_t N>
char* fn2_1_x () {
return inst_check<char [N]>() ? new char [N] : 0;
}
template <size_t N>
char* fn2_1 () {
return new char [N];
}
// Not instantiated (must not be diagnosed).
template <size_t M, size_t N>
char* fn2_2_x () {
return inst_check<char [M][N]>() ? new char [M][N] : 0;
}
template <size_t M, size_t N>
char* fn2_2 () {
return new char [M][N]; // { dg-error "size of array is too large" }
}
// Not instantiated (must not be diagnosed).
template <class T>
T* fn3_x () {
const size_t a = sizeof (T);
return inst_check<T>() ? new T [a] : 0;
}
template <class T>
T* fn3 () {
const size_t a = sizeof (T);
return new T [a]; // { dg-error "size of array is too large" }
}
struct S { char a [__SIZE_MAX__ / 8]; };
void foo ()
{
fn2_1<1>();
fn2_1<__SIZE_MAX__ / 4>();
fn2_2<__SIZE_MAX__ / 4, 4>();
fn3<S>();
}