From 80fdaad1c73fd73b30ba10d0a67fd82a3cae52b2 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Fri, 16 Mar 2018 14:56:01 -0400 Subject: [PATCH] PR c++/80227 - SFINAE and negative array size. * decl.c (compute_array_index_type): Use build_converted_constant_expr and valid_constant_size_p. From-SVN: r258604 --- gcc/cp/ChangeLog | 4 + gcc/cp/decl.c | 36 +--- gcc/testsuite/g++.dg/cpp0x/fntmpdefarg8.C | 10 + gcc/testsuite/g++.dg/gomp/pr47963.C | 2 +- gcc/testsuite/g++.dg/init/new37.C | 2 +- gcc/testsuite/g++.dg/init/new44.C | 238 +++++++++++----------- gcc/testsuite/g++.dg/ubsan/pr81530.C | 3 +- 7 files changed, 141 insertions(+), 154 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/fntmpdefarg8.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 60fe5423ba6..2957ebb7471 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,9 @@ 2018-03-16 Jason Merrill + PR c++/80227 - SFINAE and negative array size. + * decl.c (compute_array_index_type): Use + build_converted_constant_expr and valid_constant_size_p. + PR c++/84906 - silent wrong code with ambiguous conversion. * call.c (build_user_type_conversion_1): Set need_temporary_p on ambiguous conversion. diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 727bb04a394..546468bf79f 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -9514,8 +9514,6 @@ compute_array_index_type (tree name, tree size, tsubst_flags_t complain) if (!type_dependent_expression_p (size)) { - tree type = TREE_TYPE (size); - size = mark_rvalue_use (size); if (cxx_dialect < cxx11 && TREE_CODE (size) == NOP_EXPR @@ -9525,29 +9523,8 @@ compute_array_index_type (tree name, tree size, tsubst_flags_t complain) else { size = instantiate_non_dependent_expr_sfinae (size, complain); - - if (CLASS_TYPE_P (type) - && CLASSTYPE_LITERAL_P (type)) - { - size = build_expr_type_conversion (WANT_INT, size, true); - if (!size) - { - if (!(complain & tf_error)) - return error_mark_node; - if (name) - error ("size of array %qD has non-integral type %qT", - name, type); - else - error ("size of array has non-integral type %qT", type); - size = integer_one_node; - } - if (size == error_mark_node) - return error_mark_node; - type = TREE_TYPE (size); - } - - if (INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type)) - size = maybe_constant_value (size); + size = build_converted_constant_expr (size_type_node, size, complain); + size = maybe_constant_value (size); if (!TREE_CONSTANT (size)) size = osize; @@ -9557,6 +9534,7 @@ compute_array_index_type (tree name, tree size, tsubst_flags_t complain) return error_mark_node; /* The array bound must be an integer type. */ + tree type = TREE_TYPE (size); if (!INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type)) { if (!(complain & tf_error)) @@ -9566,7 +9544,6 @@ compute_array_index_type (tree name, tree size, tsubst_flags_t complain) else error ("size of array has non-integral type %qT", type); size = integer_one_node; - type = TREE_TYPE (size); } } @@ -9604,15 +9581,12 @@ compute_array_index_type (tree name, tree size, tsubst_flags_t complain) /* Normally, the array-bound will be a constant. */ if (TREE_CODE (size) == INTEGER_CST) { - /* Check to see if the array bound overflowed. Make that an - error, no matter how generous we're being. */ - constant_expression_error (size); - /* An array must have a positive number of elements. */ - if (tree_int_cst_lt (size, integer_zero_node)) + if (!valid_constant_size_p (size)) { if (!(complain & tf_error)) return error_mark_node; + if (name) error ("size of array %qD is negative", name); else diff --git a/gcc/testsuite/g++.dg/cpp0x/fntmpdefarg8.C b/gcc/testsuite/g++.dg/cpp0x/fntmpdefarg8.C new file mode 100644 index 00000000000..8d9b2d26f01 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/fntmpdefarg8.C @@ -0,0 +1,10 @@ +// PR c++/80227 +// { dg-do compile { target c++11 } } + +template +int foo (T); + +template +int foo (T, U* = 0); + +int i = foo (123); diff --git a/gcc/testsuite/g++.dg/gomp/pr47963.C b/gcc/testsuite/g++.dg/gomp/pr47963.C index 7c94e6422a7..5b0c60b80a4 100644 --- a/gcc/testsuite/g++.dg/gomp/pr47963.C +++ b/gcc/testsuite/g++.dg/gomp/pr47963.C @@ -5,7 +5,7 @@ void foo (float n) { - int A[n][n]; // { dg-error "has non-integral type" } + int A[n][n]; // { dg-error "has non-integral type|converted constant expression" } #pragma omp parallel private(A) ; } diff --git a/gcc/testsuite/g++.dg/init/new37.C b/gcc/testsuite/g++.dg/init/new37.C index 3255a696143..9ecbfd7903d 100644 --- a/gcc/testsuite/g++.dg/init/new37.C +++ b/gcc/testsuite/g++.dg/init/new37.C @@ -32,7 +32,7 @@ template void * callnew_fail_3() { - return new T[2][T::n]; // { dg-error "size of array has non-integral type" } + return new T[2][T::n]; // { dg-error "size of array has non-integral type|converted constant expression" } } struct T1 { diff --git a/gcc/testsuite/g++.dg/init/new44.C b/gcc/testsuite/g++.dg/init/new44.C index ab6e3484cc8..4ab73209e22 100644 --- a/gcc/testsuite/g++.dg/init/new44.C +++ b/gcc/testsuite/g++.dg/init/new44.C @@ -87,10 +87,10 @@ test_one_dim_short_array () static void __attribute__ ((used)) test_two_dim_char_array () { - p = new char [1][MAX]; // { dg-error "size of unnamed array" } - p = new char [1][MAX - 1]; // { dg-error "size of unnamed array" } - p = new char [1][MAX - 2]; // { dg-error "size of unnamed array" } - p = new char [1][MAX - 99]; // { dg-error "size of unnamed array" } + p = new char [1][MAX]; // { dg-error "size of (unnamed )?array" } + p = new char [1][MAX - 1]; // { dg-error "size of (unnamed )?array" } + p = new char [1][MAX - 2]; // { dg-error "size of (unnamed )?array" } + p = new char [1][MAX - 99]; // { dg-error "size of (unnamed )?array" } p = new char [1][MAX / 2]; // { dg-error "size of array" } p = new char [1][MAX / 2 - 1]; // { dg-error "size of array" } p = new char [1][MAX / 2 - 2]; // { dg-error "size of array" } @@ -104,18 +104,18 @@ test_two_dim_char_array () p = new char [1][MAX / 2 - 7]; // okay p = new char [1][MAX / 2 - 8]; // okay - p = new char [2][MAX]; // { dg-error "size of unnamed array" } - p = new char [2][MAX - 1]; // { dg-error "size of unnamed array" } - p = new char [2][MAX - 2]; // { dg-error "size of unnamed array" } + p = new char [2][MAX]; // { dg-error "size of (unnamed )?array" } + p = new char [2][MAX - 1]; // { dg-error "size of (unnamed )?array" } + p = new char [2][MAX - 2]; // { dg-error "size of (unnamed )?array" } p = new char [2][MAX / 2]; // { dg-error "size of array" } p = new char [2][MAX / 2 - 1]; // { dg-error "size of array" } p = new char [2][MAX / 2 - 2]; // { dg-error "size of array" } p = new char [2][MAX / 2 - 7]; // { dg-error "size of array" } p = new char [2][MAX / 2 - 8]; // { dg-error "size of array" } - p = new char [MAX][MAX]; // { dg-error "size of unnamed array" } - p = new char [MAX][MAX - 1]; // { dg-error "size of unnamed array" } - p = new char [MAX][MAX - 2]; // { dg-error "size of unnamed array" } + p = new char [MAX][MAX]; // { dg-error "size of (unnamed )?array" } + p = new char [MAX][MAX - 1]; // { dg-error "size of (unnamed )?array" } + p = new char [MAX][MAX - 2]; // { dg-error "size of (unnamed )?array" } p = new char [MAX][MAX / 2]; // { dg-error "size of array" } p = new char [MAX][MAX / 2 - 1]; // { dg-error "size of array" } p = new char [MAX][MAX / 2 - 2]; // { dg-error "size of array" } @@ -142,10 +142,10 @@ test_two_dim_char_array () static __attribute__ ((used)) void test_three_dim_char_array () { - p = new char [1][1][MAX]; // { dg-error "size of unnamed array" } - p = new char [1][1][MAX - 1]; // { dg-error "size of unnamed array" } - p = new char [1][1][MAX - 2]; // { dg-error "size of unnamed array" } - p = new char [1][1][MAX - 99]; // { dg-error "size of unnamed array" } + p = new char [1][1][MAX]; // { dg-error "size of (unnamed )?array" } + p = new char [1][1][MAX - 1]; // { dg-error "size of (unnamed )?array" } + p = new char [1][1][MAX - 2]; // { dg-error "size of (unnamed )?array" } + p = new char [1][1][MAX - 99]; // { dg-error "size of (unnamed )?array" } p = new char [1][1][MAX / 2]; // { dg-error "size of array" } p = new char [1][1][MAX / 2 - 1]; // { dg-error "size of array" } p = new char [1][1][MAX / 2 - 2]; // { dg-error "size of array" } @@ -159,19 +159,19 @@ test_three_dim_char_array () p = new char [1][1][MAX / 2 - 7]; // okay p = new char [1][1][MAX / 2 - 8]; // okay - p = new char [1][2][MAX]; // { dg-error "size of unnamed array" } - p = new char [1][2][MAX - 1]; // { dg-error "size of unnamed array" } - p = new char [1][2][MAX - 2]; // { dg-error "size of unnamed array" } - p = new char [1][2][MAX - 99]; // { dg-error "size of unnamed array" } - p = new char [1][2][MAX / 2]; // { dg-error "size of unnamed array" } - p = new char [1][2][MAX / 2 - 1]; // { dg-error "size of unnamed array" } - p = new char [1][2][MAX / 2 - 2]; // { dg-error "size of unnamed array" } - p = new char [1][2][MAX / 2 - 3]; // { dg-error "size of unnamed array" } - p = new char [1][2][MAX / 2 - 4]; // { dg-error "size of unnamed array" } - p = new char [1][2][MAX / 2 - 5]; // { dg-error "size of unnamed array" } - p = new char [1][2][MAX / 2 - 6]; // { dg-error "size of unnamed array" } - p = new char [1][2][MAX / 2 - 7]; // { dg-error "size of unnamed array" } - p = new char [1][2][MAX / 2 - 8]; // { dg-error "size of unnamed array" } + p = new char [1][2][MAX]; // { dg-error "size of (unnamed )?array" } + p = new char [1][2][MAX - 1]; // { dg-error "size of (unnamed )?array" } + p = new char [1][2][MAX - 2]; // { dg-error "size of (unnamed )?array" } + p = new char [1][2][MAX - 99]; // { dg-error "size of (unnamed )?array" } + p = new char [1][2][MAX / 2]; // { dg-error "size of (unnamed )?array" } + p = new char [1][2][MAX / 2 - 1]; // { dg-error "size of (unnamed )?array" } + p = new char [1][2][MAX / 2 - 2]; // { dg-error "size of (unnamed )?array" } + p = new char [1][2][MAX / 2 - 3]; // { dg-error "size of (unnamed )?array" } + p = new char [1][2][MAX / 2 - 4]; // { dg-error "size of (unnamed )?array" } + p = new char [1][2][MAX / 2 - 5]; // { dg-error "size of (unnamed )?array" } + p = new char [1][2][MAX / 2 - 6]; // { dg-error "size of (unnamed )?array" } + p = new char [1][2][MAX / 2 - 7]; // { dg-error "size of (unnamed )?array" } + p = new char [1][2][MAX / 2 - 8]; // { dg-error "size of (unnamed )?array" } p = new char [1][2][MAX / 4]; // { dg-error "size of array" } // Avoid exercising data model-dependent expressions. @@ -181,10 +181,10 @@ test_three_dim_char_array () p = new char [1][2][MAX / 4 - 3]; // okay p = new char [1][2][MAX / 4 - 4]; // okay - p = new char [2][1][MAX]; // { dg-error "size of unnamed array" } - p = new char [2][1][MAX - 1]; // { dg-error "size of unnamed array" } - p = new char [2][1][MAX - 2]; // { dg-error "size of unnamed array" } - p = new char [2][1][MAX - 99]; // { dg-error "size of unnamed array" } + p = new char [2][1][MAX]; // { dg-error "size of (unnamed )?array" } + p = new char [2][1][MAX - 1]; // { dg-error "size of (unnamed )?array" } + p = new char [2][1][MAX - 2]; // { dg-error "size of (unnamed )?array" } + p = new char [2][1][MAX - 99]; // { dg-error "size of (unnamed )?array" } p = new char [2][1][MAX / 2]; // { dg-error "size of array" } p = new char [2][1][MAX / 2 - 1]; // { dg-error "size of array" } p = new char [2][1][MAX / 2 - 2]; // { dg-error "size of array" } @@ -203,19 +203,19 @@ test_three_dim_char_array () p = new char [2][1][MAX / 4 - 3]; // okay p = new char [2][1][MAX / 4 - 4]; // okay - p = new char [2][2][MAX]; // { dg-error "size of unnamed array" } - p = new char [2][2][MAX - 1]; // { dg-error "size of unnamed array" } - p = new char [2][2][MAX - 2]; // { dg-error "size of unnamed array" } - p = new char [2][2][MAX - 99]; // { dg-error "size of unnamed array" } - p = new char [2][2][MAX / 2]; // { dg-error "size of unnamed array" } - p = new char [2][2][MAX / 2 - 1]; // { dg-error "size of unnamed array" } - p = new char [2][2][MAX / 2 - 2]; // { dg-error "size of unnamed array" } - p = new char [2][2][MAX / 2 - 3]; // { dg-error "size of unnamed array" } - p = new char [2][2][MAX / 2 - 4]; // { dg-error "size of unnamed array" } - p = new char [2][2][MAX / 2 - 5]; // { dg-error "size of unnamed array" } - p = new char [2][2][MAX / 2 - 6]; // { dg-error "size of unnamed array" } - p = new char [2][2][MAX / 2 - 7]; // { dg-error "size of unnamed array" } - p = new char [2][2][MAX / 2 - 8]; // { dg-error "size of unnamed array" } + p = new char [2][2][MAX]; // { dg-error "size of (unnamed )?array" } + p = new char [2][2][MAX - 1]; // { dg-error "size of (unnamed )?array" } + p = new char [2][2][MAX - 2]; // { dg-error "size of (unnamed )?array" } + p = new char [2][2][MAX - 99]; // { dg-error "size of (unnamed )?array" } + p = new char [2][2][MAX / 2]; // { dg-error "size of (unnamed )?array" } + p = new char [2][2][MAX / 2 - 1]; // { dg-error "size of (unnamed )?array" } + p = new char [2][2][MAX / 2 - 2]; // { dg-error "size of (unnamed )?array" } + p = new char [2][2][MAX / 2 - 3]; // { dg-error "size of (unnamed )?array" } + p = new char [2][2][MAX / 2 - 4]; // { dg-error "size of (unnamed )?array" } + p = new char [2][2][MAX / 2 - 5]; // { dg-error "size of (unnamed )?array" } + p = new char [2][2][MAX / 2 - 6]; // { dg-error "size of (unnamed )?array" } + p = new char [2][2][MAX / 2 - 7]; // { dg-error "size of (unnamed )?array" } + p = new char [2][2][MAX / 2 - 8]; // { dg-error "size of (unnamed )?array" } p = new char [2][2][MAX / 4]; // { dg-error "size of array" } p = new char [2][2][MAX / 4 - 1]; // { dg-error "size of array" } p = new char [2][2][MAX / 4 - 2]; // { dg-error "size of array" } @@ -227,19 +227,19 @@ test_three_dim_char_array () p = new char [2][2][MAX / 8 - 2]; p = new char [2][2][MAX / 8 - 3]; - p = new char [2][MAX][2]; // { dg-error "size of unnamed array" } - p = new char [2][MAX - 1][2]; // { dg-error "size of unnamed array" } - p = new char [2][MAX - 2][2]; // { dg-error "size of unnamed array" } - p = new char [2][MAX - 99][2]; // { dg-error "size of unnamed array" } - p = new char [2][MAX / 2][2]; // { dg-error "size of unnamed array" } - p = new char [2][MAX / 2 - 1][2]; // { dg-error "size of unnamed array" } - p = new char [2][MAX / 2 - 2][2]; // { dg-error "size of unnamed array" } - p = new char [2][MAX / 2 - 3][2]; // { dg-error "size of unnamed array" } - p = new char [2][MAX / 2 - 4][2]; // { dg-error "size of unnamed array" } - p = new char [2][MAX / 2 - 5][2]; // { dg-error "size of unnamed array" } - p = new char [2][MAX / 2 - 6][2]; // { dg-error "size of unnamed array" } - p = new char [2][MAX / 2 - 7][2]; // { dg-error "size of unnamed array" } - p = new char [2][MAX / 2 - 8][2]; // { dg-error "size of unnamed array" } + p = new char [2][MAX][2]; // { dg-error "size of (unnamed )?array" } + p = new char [2][MAX - 1][2]; // { dg-error "size of (unnamed )?array" } + p = new char [2][MAX - 2][2]; // { dg-error "size of (unnamed )?array" } + p = new char [2][MAX - 99][2]; // { dg-error "size of (unnamed )?array" } + p = new char [2][MAX / 2][2]; // { dg-error "size of (unnamed )?array" } + p = new char [2][MAX / 2 - 1][2]; // { dg-error "size of (unnamed )?array" } + p = new char [2][MAX / 2 - 2][2]; // { dg-error "size of (unnamed )?array" } + p = new char [2][MAX / 2 - 3][2]; // { dg-error "size of (unnamed )?array" } + p = new char [2][MAX / 2 - 4][2]; // { dg-error "size of (unnamed )?array" } + p = new char [2][MAX / 2 - 5][2]; // { dg-error "size of (unnamed )?array" } + p = new char [2][MAX / 2 - 6][2]; // { dg-error "size of (unnamed )?array" } + p = new char [2][MAX / 2 - 7][2]; // { dg-error "size of (unnamed )?array" } + p = new char [2][MAX / 2 - 8][2]; // { dg-error "size of (unnamed )?array" } p = new char [2][MAX / 4][2]; // { dg-error "size of array" } p = new char [2][MAX / 4 - 1][2]; // { dg-error "size of array" } p = new char [2][MAX / 4 - 2][2]; // { dg-error "size of array" } @@ -275,11 +275,11 @@ test_three_dim_char_array () p = new char [MAX / 8 - 2][2][2]; p = new char [MAX / 8 - 3][2][2]; - p = new char [MAX][MAX][MAX]; // { dg-error "size of unnamed array" } - p = new char [MAX][MAX][MAX / 2]; // { dg-error "size of unnamed array" } - p = new char [MAX][MAX / 2][MAX]; // { dg-error "size of unnamed array" } - p = new char [MAX][MAX / 2][MAX / 2]; // { dg-error "size of unnamed array" } - p = new char [MAX / 2][MAX / 2][MAX / 2]; // { dg-error "size of unnamed array" } + p = new char [MAX][MAX][MAX]; // { dg-error "size of (unnamed )?array" } + p = new char [MAX][MAX][MAX / 2]; // { dg-error "size of (unnamed )?array" } + p = new char [MAX][MAX / 2][MAX]; // { dg-error "size of (unnamed )?array" } + p = new char [MAX][MAX / 2][MAX / 2]; // { dg-error "size of (unnamed )?array" } + p = new char [MAX / 2][MAX / 2][MAX / 2]; // { dg-error "size of (unnamed )?array" } } // Exercise new expression with N-dimensional arrays where N is @@ -342,10 +342,10 @@ test_one_dim_byte_array (void *p) static void __attribute__ ((used)) test_placement_two_dim_byte_struct_array (void *p) { - p = new (p) B [1][MAX]; // { dg-error "size of unnamed array" } - p = new (p) B [1][MAX - 1]; // { dg-error "size of unnamed array" } - p = new (p) B [1][MAX - 2]; // { dg-error "size of unnamed array" } - p = new (p) B [1][MAX - 99]; // { dg-error "size of unnamed array" } + p = new (p) B [1][MAX]; // { dg-error "size of (unnamed )?array" } + p = new (p) B [1][MAX - 1]; // { dg-error "size of (unnamed )?array" } + p = new (p) B [1][MAX - 2]; // { dg-error "size of (unnamed )?array" } + p = new (p) B [1][MAX - 99]; // { dg-error "size of (unnamed )?array" } p = new (p) B [1][MAX / 2]; // { dg-error "size of array" } p = new (p) B [1][MAX / 2 - 1]; // { dg-error "size of array" } p = new (p) B [1][MAX / 2 - 2]; // { dg-error "size of array" } @@ -359,18 +359,18 @@ test_placement_two_dim_byte_struct_array (void *p) p = new (p) B [1][MAX / 2 - 7]; // okay p = new (p) B [1][MAX / 2 - 8]; // okay - p = new (p) B [2][MAX]; // { dg-error "size of unnamed array" } - p = new (p) B [2][MAX - 1]; // { dg-error "size of unnamed array" } - p = new (p) B [2][MAX - 2]; // { dg-error "size of unnamed array" } + p = new (p) B [2][MAX]; // { dg-error "size of (unnamed )?array" } + p = new (p) B [2][MAX - 1]; // { dg-error "size of (unnamed )?array" } + p = new (p) B [2][MAX - 2]; // { dg-error "size of (unnamed )?array" } p = new (p) B [2][MAX / 2]; // { dg-error "size of array" } p = new (p) B [2][MAX / 2 - 1]; // { dg-error "size of array" } p = new (p) B [2][MAX / 2 - 2]; // { dg-error "size of array" } p = new (p) B [2][MAX / 2 - 7]; // { dg-error "size of array" } p = new (p) B [2][MAX / 2 - 8]; // { dg-error "size of array" } - p = new (p) B [MAX][MAX]; // { dg-error "size of unnamed array" } - p = new (p) B [MAX][MAX - 1]; // { dg-error "size of unnamed array" } - p = new (p) B [MAX][MAX - 2]; // { dg-error "size of unnamed array" } + p = new (p) B [MAX][MAX]; // { dg-error "size of (unnamed )?array" } + p = new (p) B [MAX][MAX - 1]; // { dg-error "size of (unnamed )?array" } + p = new (p) B [MAX][MAX - 2]; // { dg-error "size of (unnamed )?array" } p = new (p) B [MAX][MAX / 2]; // { dg-error "size of array" } p = new (p) B [MAX][MAX / 2 - 1]; // { dg-error "size of array" } p = new (p) B [MAX][MAX / 2 - 2]; // { dg-error "size of array" } @@ -397,10 +397,10 @@ test_placement_two_dim_byte_struct_array (void *p) static __attribute__ ((used)) void test_placement_three_dim_byte_struct_array (void *p) { - p = new (p) B [1][1][MAX]; // { dg-error "size of unnamed array" } - p = new (p) B [1][1][MAX - 1]; // { dg-error "size of unnamed array" } - p = new (p) B [1][1][MAX - 2]; // { dg-error "size of unnamed array" } - p = new (p) B [1][1][MAX - 99]; // { dg-error "size of unnamed array" } + p = new (p) B [1][1][MAX]; // { dg-error "size of (unnamed )?array" } + p = new (p) B [1][1][MAX - 1]; // { dg-error "size of (unnamed )?array" } + p = new (p) B [1][1][MAX - 2]; // { dg-error "size of (unnamed )?array" } + p = new (p) B [1][1][MAX - 99]; // { dg-error "size of (unnamed )?array" } p = new (p) B [1][1][MAX / 2]; // { dg-error "size of array" } p = new (p) B [1][1][MAX / 2 - 1]; // { dg-error "size of array" } p = new (p) B [1][1][MAX / 2 - 2]; // { dg-error "size of array" } @@ -414,19 +414,19 @@ test_placement_three_dim_byte_struct_array (void *p) p = new (p) B [1][1][MAX / 2 - 7]; // okay p = new (p) B [1][1][MAX / 2 - 8]; // okay - p = new (p) B [1][2][MAX]; // { dg-error "size of unnamed array" } - p = new (p) B [1][2][MAX - 1]; // { dg-error "size of unnamed array" } - p = new (p) B [1][2][MAX - 2]; // { dg-error "size of unnamed array" } - p = new (p) B [1][2][MAX - 99]; // { dg-error "size of unnamed array" } - p = new (p) B [1][2][MAX / 2]; // { dg-error "size of unnamed array" } - p = new (p) B [1][2][MAX / 2 - 1]; // { dg-error "size of unnamed array" } - p = new (p) B [1][2][MAX / 2 - 2]; // { dg-error "size of unnamed array" } - p = new (p) B [1][2][MAX / 2 - 3]; // { dg-error "size of unnamed array" } - p = new (p) B [1][2][MAX / 2 - 4]; // { dg-error "size of unnamed array" } - p = new (p) B [1][2][MAX / 2 - 5]; // { dg-error "size of unnamed array" } - p = new (p) B [1][2][MAX / 2 - 6]; // { dg-error "size of unnamed array" } - p = new (p) B [1][2][MAX / 2 - 7]; // { dg-error "size of unnamed array" } - p = new (p) B [1][2][MAX / 2 - 8]; // { dg-error "size of unnamed array" } + p = new (p) B [1][2][MAX]; // { dg-error "size of (unnamed )?array" } + p = new (p) B [1][2][MAX - 1]; // { dg-error "size of (unnamed )?array" } + p = new (p) B [1][2][MAX - 2]; // { dg-error "size of (unnamed )?array" } + p = new (p) B [1][2][MAX - 99]; // { dg-error "size of (unnamed )?array" } + p = new (p) B [1][2][MAX / 2]; // { dg-error "size of (unnamed )?array" } + p = new (p) B [1][2][MAX / 2 - 1]; // { dg-error "size of (unnamed )?array" } + p = new (p) B [1][2][MAX / 2 - 2]; // { dg-error "size of (unnamed )?array" } + p = new (p) B [1][2][MAX / 2 - 3]; // { dg-error "size of (unnamed )?array" } + p = new (p) B [1][2][MAX / 2 - 4]; // { dg-error "size of (unnamed )?array" } + p = new (p) B [1][2][MAX / 2 - 5]; // { dg-error "size of (unnamed )?array" } + p = new (p) B [1][2][MAX / 2 - 6]; // { dg-error "size of (unnamed )?array" } + p = new (p) B [1][2][MAX / 2 - 7]; // { dg-error "size of (unnamed )?array" } + p = new (p) B [1][2][MAX / 2 - 8]; // { dg-error "size of (unnamed )?array" } p = new (p) B [1][2][MAX / 4]; // { dg-error "size of array" } // Avoid exercising data model-dependent expressions. @@ -436,10 +436,10 @@ test_placement_three_dim_byte_struct_array (void *p) p = new (p) B [1][2][MAX / 4 - 3]; // okay p = new (p) B [1][2][MAX / 4 - 4]; // okay - p = new (p) B [2][1][MAX]; // { dg-error "size of unnamed array" } - p = new (p) B [2][1][MAX - 1]; // { dg-error "size of unnamed array" } - p = new (p) B [2][1][MAX - 2]; // { dg-error "size of unnamed array" } - p = new (p) B [2][1][MAX - 99]; // { dg-error "size of unnamed array" } + p = new (p) B [2][1][MAX]; // { dg-error "size of (unnamed )?array" } + p = new (p) B [2][1][MAX - 1]; // { dg-error "size of (unnamed )?array" } + p = new (p) B [2][1][MAX - 2]; // { dg-error "size of (unnamed )?array" } + p = new (p) B [2][1][MAX - 99]; // { dg-error "size of (unnamed )?array" } p = new (p) B [2][1][MAX / 2]; // { dg-error "size of array" } p = new (p) B [2][1][MAX / 2 - 1]; // { dg-error "size of array" } p = new (p) B [2][1][MAX / 2 - 2]; // { dg-error "size of array" } @@ -458,19 +458,19 @@ test_placement_three_dim_byte_struct_array (void *p) p = new (p) B [2][1][MAX / 4 - 3]; // okay p = new (p) B [2][1][MAX / 4 - 4]; // okay - p = new (p) B [2][2][MAX]; // { dg-error "size of unnamed array" } - p = new (p) B [2][2][MAX - 1]; // { dg-error "size of unnamed array" } - p = new (p) B [2][2][MAX - 2]; // { dg-error "size of unnamed array" } - p = new (p) B [2][2][MAX - 99]; // { dg-error "size of unnamed array" } - p = new (p) B [2][2][MAX / 2]; // { dg-error "size of unnamed array" } - p = new (p) B [2][2][MAX / 2 - 1]; // { dg-error "size of unnamed array" } - p = new (p) B [2][2][MAX / 2 - 2]; // { dg-error "size of unnamed array" } - p = new (p) B [2][2][MAX / 2 - 3]; // { dg-error "size of unnamed array" } - p = new (p) B [2][2][MAX / 2 - 4]; // { dg-error "size of unnamed array" } - p = new (p) B [2][2][MAX / 2 - 5]; // { dg-error "size of unnamed array" } - p = new (p) B [2][2][MAX / 2 - 6]; // { dg-error "size of unnamed array" } - p = new (p) B [2][2][MAX / 2 - 7]; // { dg-error "size of unnamed array" } - p = new (p) B [2][2][MAX / 2 - 8]; // { dg-error "size of unnamed array" } + p = new (p) B [2][2][MAX]; // { dg-error "size of (unnamed )?array" } + p = new (p) B [2][2][MAX - 1]; // { dg-error "size of (unnamed )?array" } + p = new (p) B [2][2][MAX - 2]; // { dg-error "size of (unnamed )?array" } + p = new (p) B [2][2][MAX - 99]; // { dg-error "size of (unnamed )?array" } + p = new (p) B [2][2][MAX / 2]; // { dg-error "size of (unnamed )?array" } + p = new (p) B [2][2][MAX / 2 - 1]; // { dg-error "size of (unnamed )?array" } + p = new (p) B [2][2][MAX / 2 - 2]; // { dg-error "size of (unnamed )?array" } + p = new (p) B [2][2][MAX / 2 - 3]; // { dg-error "size of (unnamed )?array" } + p = new (p) B [2][2][MAX / 2 - 4]; // { dg-error "size of (unnamed )?array" } + p = new (p) B [2][2][MAX / 2 - 5]; // { dg-error "size of (unnamed )?array" } + p = new (p) B [2][2][MAX / 2 - 6]; // { dg-error "size of (unnamed )?array" } + p = new (p) B [2][2][MAX / 2 - 7]; // { dg-error "size of (unnamed )?array" } + p = new (p) B [2][2][MAX / 2 - 8]; // { dg-error "size of (unnamed )?array" } p = new (p) B [2][2][MAX / 4]; // { dg-error "size of array" } p = new (p) B [2][2][MAX / 4 - 1]; // { dg-error "size of array" } p = new (p) B [2][2][MAX / 4 - 2]; // { dg-error "size of array" } @@ -482,19 +482,19 @@ test_placement_three_dim_byte_struct_array (void *p) p = new (p) B [2][2][MAX / 8 - 2]; p = new (p) B [2][2][MAX / 8 - 3]; - p = new (p) B [2][MAX][2]; // { dg-error "size of unnamed array" } - p = new (p) B [2][MAX - 1][2]; // { dg-error "size of unnamed array" } - p = new (p) B [2][MAX - 2][2]; // { dg-error "size of unnamed array" } - p = new (p) B [2][MAX - 99][2]; // { dg-error "size of unnamed array" } - p = new (p) B [2][MAX / 2][2]; // { dg-error "size of unnamed array" } - p = new (p) B [2][MAX / 2 - 1][2]; // { dg-error "size of unnamed array" } - p = new (p) B [2][MAX / 2 - 2][2]; // { dg-error "size of unnamed array" } - p = new (p) B [2][MAX / 2 - 3][2]; // { dg-error "size of unnamed array" } - p = new (p) B [2][MAX / 2 - 4][2]; // { dg-error "size of unnamed array" } - p = new (p) B [2][MAX / 2 - 5][2]; // { dg-error "size of unnamed array" } - p = new (p) B [2][MAX / 2 - 6][2]; // { dg-error "size of unnamed array" } - p = new (p) B [2][MAX / 2 - 7][2]; // { dg-error "size of unnamed array" } - p = new (p) B [2][MAX / 2 - 8][2]; // { dg-error "size of unnamed array" } + p = new (p) B [2][MAX][2]; // { dg-error "size of (unnamed )?array" } + p = new (p) B [2][MAX - 1][2]; // { dg-error "size of (unnamed )?array" } + p = new (p) B [2][MAX - 2][2]; // { dg-error "size of (unnamed )?array" } + p = new (p) B [2][MAX - 99][2]; // { dg-error "size of (unnamed )?array" } + p = new (p) B [2][MAX / 2][2]; // { dg-error "size of (unnamed )?array" } + p = new (p) B [2][MAX / 2 - 1][2]; // { dg-error "size of (unnamed )?array" } + p = new (p) B [2][MAX / 2 - 2][2]; // { dg-error "size of (unnamed )?array" } + p = new (p) B [2][MAX / 2 - 3][2]; // { dg-error "size of (unnamed )?array" } + p = new (p) B [2][MAX / 2 - 4][2]; // { dg-error "size of (unnamed )?array" } + p = new (p) B [2][MAX / 2 - 5][2]; // { dg-error "size of (unnamed )?array" } + p = new (p) B [2][MAX / 2 - 6][2]; // { dg-error "size of (unnamed )?array" } + p = new (p) B [2][MAX / 2 - 7][2]; // { dg-error "size of (unnamed )?array" } + p = new (p) B [2][MAX / 2 - 8][2]; // { dg-error "size of (unnamed )?array" } p = new (p) B [2][MAX / 4][2]; // { dg-error "size of array" } p = new (p) B [2][MAX / 4 - 1][2]; // { dg-error "size of array" } p = new (p) B [2][MAX / 4 - 2][2]; // { dg-error "size of array" } diff --git a/gcc/testsuite/g++.dg/ubsan/pr81530.C b/gcc/testsuite/g++.dg/ubsan/pr81530.C index e21724686c4..1fbbaa9d1e2 100644 --- a/gcc/testsuite/g++.dg/ubsan/pr81530.C +++ b/gcc/testsuite/g++.dg/ubsan/pr81530.C @@ -2,5 +2,4 @@ /* { dg-do compile } */ /* { dg-options "-fsanitize=undefined" } */ -int a[(long) 4e20]; /* { dg-error "overflow in constant expression" } */ -/* { dg-error "size of array .a. is too large" "" { target *-*-* } .-1 } */ +int a[(long) 4e20]; /* { dg-error "size of array .a. is (too large|negative)" } */ -- 2.30.2