From 28a8cef1e240989c199dfd8538c826c134098f85 Mon Sep 17 00:00:00 2001 From: Martin Sebor Date: Mon, 11 Feb 2019 17:35:17 +0000 Subject: [PATCH] PR c++/87996 - size of array is negative error when SIZE_MAX/2 < sizeof(array) <= SIZE_MAX gcc/ChangeLog: PR c++/87996 * builtins.c (max_object_size): Move from here... * builtins.h (max_object_size): ...and here... * tree.c (max_object_size): ...to here... * tree.h (max_object_size): ...and here. gcc/c-family/ChangeLog: PR c++/87996 * c-common.c (invalid_array_size_error): New function. (valid_array_size_p): Call it. Handle size as well as type. * c-common.h (valid_constant_size_p): New function. (enum cst_size_error): New type. gcc/cp/ChangeLog: PR c++/87996 * decl.c (compute_array_index_type_loc): Preserve signed sizes for diagnostics. Call valid_array_size_p instead of error. * init.c (build_new_1): Compute size for diagnostic. Call invalid_array_size_error (build_new): Call valid_array_size_p instead of error. gcc/testsuite/ChangeLog: PR c++/87996 * c-c++-common/array-5.c: New test. * c-c++-common/pr68107.c: Adjust text of diagnostics. * g++.dg/init/new38.C: Same. * g++.dg/init/new43.C: Same. * g++.dg/init/new44.C: Same. * g++.dg/init/new46.C: Same. * g++.dg/other/large-size-array.C: Same. * g++.dg/other/new-size-type.C: Same. * g++.dg/template/array30.C: Same. * g++.dg/template/array32.C: New test. * g++.dg/template/dependent-name3.C: Adjust. * gcc.dg/large-size-array-3.c: Same. * gcc.dg/large-size-array-5.c: Same. * gcc.dg/large-size-array.c: Same. * g++.old-deja/g++.brendan/array1.C: Same. * g++.old-deja/g++.mike/p6149.C: Same. From-SVN: r268774 --- gcc/ChangeLog | 8 + gcc/builtins.c | 9 - gcc/builtins.h | 1 - gcc/c-family/ChangeLog | 8 + gcc/c-family/c-common.c | 85 ++- gcc/c-family/c-common.h | 4 +- gcc/cp/ChangeLog | 9 + gcc/cp/decl.c | 42 +- gcc/cp/init.c | 31 +- gcc/testsuite/ChangeLog | 20 + gcc/testsuite/c-c++-common/array-5.c | 60 ++ gcc/testsuite/c-c++-common/pr68107.c | 36 +- gcc/testsuite/g++.dg/init/new38.C | 10 +- gcc/testsuite/g++.dg/init/new43.C | 183 ++++--- gcc/testsuite/g++.dg/init/new44.C | 518 +++++++++--------- gcc/testsuite/g++.dg/init/new46.C | 4 +- gcc/testsuite/g++.dg/other/large-size-array.C | 2 +- gcc/testsuite/g++.dg/other/new-size-type.C | 2 +- gcc/testsuite/g++.dg/template/array30.C | 2 +- gcc/testsuite/g++.dg/template/array32.C | 27 + .../g++.dg/template/dependent-name3.C | 2 +- gcc/testsuite/g++.dg/ubsan/pr81530.C | 2 +- .../g++.old-deja/g++.brendan/array1.C | 2 +- gcc/testsuite/g++.old-deja/g++.mike/p6149.C | 2 +- gcc/testsuite/gcc.dg/large-size-array-3.c | 2 +- gcc/testsuite/gcc.dg/large-size-array-5.c | 4 +- gcc/testsuite/gcc.dg/large-size-array.c | 2 +- gcc/tree.c | 46 +- gcc/tree.h | 13 +- 29 files changed, 697 insertions(+), 439 deletions(-) create mode 100644 gcc/testsuite/c-c++-common/array-5.c create mode 100644 gcc/testsuite/g++.dg/template/array32.C diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 4a66632e740..a8b815658c8 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2019-02-11 Martin Sebor + + PR c++/87996 + * builtins.c (max_object_size): Move from here... + * builtins.h (max_object_size): ...and here... + * tree.c (max_object_size): ...to here... + * tree.h (max_object_size): ...and here. + 2019-02-11 Bill Schmidt * config/rs6000/rs6000.c (rs6000_gimple_fold_builtin): Shift-right diff --git a/gcc/builtins.c b/gcc/builtins.c index 6135bc5a4e2..693e8937918 100644 --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -11210,12 +11210,3 @@ target_char_cst_p (tree t, char *p) *p = (char)tree_to_uhwi (t); return true; } - -/* Return the maximum object size. */ - -tree -max_object_size (void) -{ - /* To do: Make this a configurable parameter. */ - return TYPE_MAX_VALUE (ptrdiff_type_node); -} diff --git a/gcc/builtins.h b/gcc/builtins.h index 75e3240ad33..3ec4ba09b66 100644 --- a/gcc/builtins.h +++ b/gcc/builtins.h @@ -150,6 +150,5 @@ extern internal_fn replacement_internal_fn (gcall *); extern void warn_string_no_nul (location_t, const char *, tree, tree); extern tree unterminated_array (tree, tree * = NULL, bool * = NULL); -extern tree max_object_size (); #endif /* GCC_BUILTINS_H */ diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index dd1173f0487..7dae7bf530a 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,11 @@ +2019-02-11 Martin Sebor + + PR c++/87996 + * c-common.c (invalid_array_size_error): New function. + (valid_array_size_p): Call it. Handle size as well as type. + * c-common.h (valid_constant_size_p): New function. + (enum cst_size_error): New type. + 2019-01-31 David Malcolm PR c/89122 diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c index d3b5879a2b2..ae23e59f652 100644 --- a/gcc/c-family/c-common.c +++ b/gcc/c-family/c-common.c @@ -8231,29 +8231,82 @@ reject_gcc_builtin (const_tree expr, location_t loc /* = UNKNOWN_LOCATION */) return false; } +/* Issue an ERROR for an invalid SIZE of array NAME which is null + for unnamed arrays. */ + +void +invalid_array_size_error (location_t loc, cst_size_error error, + const_tree size, const_tree name) +{ + tree maxsize = max_object_size (); + switch (error) + { + case cst_size_negative: + if (name) + error_at (loc, "size %qE of array %qE is negative", + size, name); + else + error_at (loc, "size %qE of array is negative", + size); + break; + case cst_size_too_big: + if (name) + error_at (loc, "size %qE of array %qE exceeds maximum " + "object size %qE", size, name, maxsize); + else + error_at (loc, "size %qE of array exceeds maximum " + "object size %qE", size, maxsize); + break; + case cst_size_overflow: + if (name) + error_at (loc, "size of array %qE exceeds maximum " + "object size %qE", name, maxsize); + else + error_at (loc, "size of array exceeds maximum " + "object size %qE", maxsize); + break; + default: + gcc_unreachable (); + } +} + /* Check if array size calculations overflow or if the array covers more than half of the address space. Return true if the size of the array - is valid, false otherwise. TYPE is the type of the array and NAME is - the name of the array, or NULL_TREE for unnamed arrays. */ + is valid, false otherwise. T is either the type of the array or its + size, and NAME is the name of the array, or null for unnamed arrays. */ bool -valid_array_size_p (location_t loc, tree type, tree name, bool complain) +valid_array_size_p (location_t loc, const_tree t, tree name, bool complain) { - if (type != error_mark_node - && COMPLETE_TYPE_P (type) - && TREE_CODE (TYPE_SIZE_UNIT (type)) == INTEGER_CST - && !valid_constant_size_p (TYPE_SIZE_UNIT (type))) + if (t == error_mark_node) + return true; + + const_tree size; + if (TYPE_P (t)) { - if (complain) - { - if (name) - error_at (loc, "size of array %qE is too large", name); - else - error_at (loc, "size of unnamed array is too large"); - } - return false; + if (!COMPLETE_TYPE_P (t)) + return true; + size = TYPE_SIZE_UNIT (t); } - return true; + else + size = t; + + if (TREE_CODE (size) != INTEGER_CST) + return true; + + cst_size_error error; + if (valid_constant_size_p (size, &error)) + return true; + + if (!complain) + return false; + + if (TREE_CODE (TREE_TYPE (size)) == ENUMERAL_TYPE) + /* Show the value of the enumerator rather than its name. */ + size = convert (ssizetype, const_cast (size)); + + invalid_array_size_error (loc, error, size, name); + return false; } /* Read SOURCE_DATE_EPOCH from environment to have a deterministic diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h index 69cb76cf49d..394a0ea1c89 100644 --- a/gcc/c-family/c-common.h +++ b/gcc/c-family/c-common.h @@ -1270,7 +1270,9 @@ extern tree find_inv_trees (tree *, int *, void *); extern tree replace_inv_trees (tree *, int *, void *); extern bool reject_gcc_builtin (const_tree, location_t = UNKNOWN_LOCATION); -extern bool valid_array_size_p (location_t, tree, tree, bool = true); +extern bool valid_array_size_p (location_t, const_tree, tree, bool = true); +extern void invalid_array_size_error (location_t, cst_size_error, + const_tree, const_tree); /* In c-warn.c. */ extern void constant_expression_warning (tree); diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 3cafaaad933..76f22f5e363 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,12 @@ +2019-02-11 Martin Sebor + + PR c++/87996 + * decl.c (compute_array_index_type_loc): Preserve signed sizes + for diagnostics. Call valid_array_size_p instead of error. + * init.c (build_new_1): Compute size for diagnostic. Call + invalid_array_size_error + (build_new): Call valid_array_size_p instead of error. + 2019-02-07 Alexandre Oliva PR c++/86218 diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 65ba812deb6..40381978312 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -9652,17 +9652,21 @@ static tree compute_array_index_type_loc (location_t name_loc, tree name, tree size, tsubst_flags_t complain) { - tree itype; - tree osize = size; - if (error_operand_p (size)) return error_mark_node; + /* The type of the index being computed. */ + tree itype; + + /* The original numeric size as seen in the source code before + conversion to size_t. */ + tree origsize = size; + location_t loc = cp_expr_loc_or_loc (size, name ? name_loc : input_location); if (!type_dependent_expression_p (size)) { - osize = size = mark_rvalue_use (size); + origsize = size = mark_rvalue_use (size); if (cxx_dialect < cxx11 && TREE_CODE (size) == NOP_EXPR && TREE_SIDE_EFFECTS (size)) @@ -9679,7 +9683,7 @@ compute_array_index_type_loc (location_t name_loc, tree name, tree size, /*manifestly_const_eval=*/true); if (!TREE_CONSTANT (size)) - size = osize; + size = origsize; } if (error_operand_p (size)) @@ -9740,16 +9744,30 @@ compute_array_index_type_loc (location_t name_loc, tree name, tree size, /* Normally, the array-bound will be a constant. */ if (TREE_CODE (size) == INTEGER_CST) { - /* An array must have a positive number of elements. */ - if (!valid_constant_size_p (size)) + /* The size to use in diagnostics that reflects the constant + size used in the source, rather than SIZE massaged above. */ + tree diagsize = size; + + /* If the original size before conversion to size_t was signed + and negative, convert it to ssizetype to restore the sign. */ + if (!TYPE_UNSIGNED (TREE_TYPE (origsize)) + && TREE_CODE (size) == INTEGER_CST + && tree_int_cst_sign_bit (size)) + { + diagsize = fold_convert (ssizetype, size); + + /* Clear the overflow bit that may have been set as a result + of the conversion from the sizetype of the new size to + ssizetype. */ + TREE_OVERFLOW (diagsize) = false; + } + + /* Verify that the array has a positive number of elements + and issue the appropriate diagnostic if it doesn't. */ + if (!valid_array_size_p (loc, diagsize, name, (complain & tf_error))) { if (!(complain & tf_error)) return error_mark_node; - - if (name) - error_at (loc, "size of array %qD is negative", name); - else - error_at (loc, "size of array is negative"); size = integer_one_node; } /* As an extension we allow zero-sized arrays. */ diff --git a/gcc/cp/init.c b/gcc/cp/init.c index efbda3a13a6..606d246ef94 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -3086,7 +3086,21 @@ build_new_1 (vec **placement, tree type, tree nelts, if (overflow || wi::gtu_p (inner_size, max_size)) { if (complain & tf_error) - error ("size of array is too large"); + { + cst_size_error error; + if (overflow) + error = cst_size_overflow; + else + { + error = cst_size_too_big; + size = size_binop (MULT_EXPR, size, + wide_int_to_tree (sizetype, + inner_nelts_count)); + size = cp_fully_fold (size); + } + invalid_array_size_error (input_location, error, size, + /*name=*/NULL_TREE); + } return error_mark_node; } @@ -3105,7 +3119,11 @@ build_new_1 (vec **placement, tree type, tree nelts, isn't explicitly stated but it's enforced anyway -- see grokdeclarator in cp/decl.c). */ if (complain & tf_error) - error ("size of array is too large"); + { + size = cp_fully_fold (size); + invalid_array_size_error (input_location, cst_size_too_big, + size, NULL_TREE); + } return error_mark_node; } } @@ -3747,12 +3765,9 @@ build_new (vec **placement, tree type, tree nelts, less than zero. ... If the expression is a constant expression, the program is ill-fomed. */ if (TREE_CODE (cst_nelts) == INTEGER_CST - && tree_int_cst_sgn (cst_nelts) == -1) - { - if (complain & tf_error) - error ("size of array is negative"); - return error_mark_node; - } + && !valid_array_size_p (input_location, cst_nelts, NULL_TREE, + complain & tf_error)) + return error_mark_node; nelts = mark_rvalue_use (nelts); nelts = cp_save_expr (cp_convert (sizetype, nelts, complain)); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 011959ab818..0406b6b0dce 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,23 @@ +2019-02-11 Martin Sebor + + PR c++/87996 + * c-c++-common/array-5.c: New test. + * c-c++-common/pr68107.c: Adjust text of diagnostics. + * g++.dg/init/new38.C: Same. + * g++.dg/init/new43.C: Same. + * g++.dg/init/new44.C: Same. + * g++.dg/init/new46.C: Same. + * g++.dg/other/large-size-array.C: Same. + * g++.dg/other/new-size-type.C: Same. + * g++.dg/template/array30.C: Same. + * g++.dg/template/array32.C: New test. + * g++.dg/template/dependent-name3.C: Adjust. + * gcc.dg/large-size-array-3.c: Same. + * gcc.dg/large-size-array-5.c: Same. + * gcc.dg/large-size-array.c: Same. + * g++.old-deja/g++.brendan/array1.C: Same. + * g++.old-deja/g++.mike/p6149.C: Same. + 2019-02-11 Martin Sebor * gcc.dg/tree-prof/inliner-1.c: Correct comments. diff --git a/gcc/testsuite/c-c++-common/array-5.c b/gcc/testsuite/c-c++-common/array-5.c new file mode 100644 index 00000000000..bf17d1bb53d --- /dev/null +++ b/gcc/testsuite/c-c++-common/array-5.c @@ -0,0 +1,60 @@ +/* PR c++/87996 - "size of array is negative" error when SIZE_MAX/2 < sizeof(array) <= SIZE_MAX + { dg-do compile } + { dg-options "-ftrack-macro-expansion=0" } */ + +#define INT16_MAX __INT16_MAX__ +#define UINT16_MAX ((INT16_MAX << 1) + 1) + +#define DIFF_MAX __PTRDIFF_MAX__ +#define SIZE_MAX __SIZE_MAX__ + +typedef __INT16_TYPE__ int16_t; +typedef __INT32_TYPE__ int32_t; +typedef __SIZE_TYPE__ size_t; + +/* Verify errors for types. */ + +typedef char i8a1_d_m1_t[DIFF_MAX - 1]; +/* The following should also be diagnosed because the difference between + &i8a1_dx[0] and &i8a1_dx[sizeof i8a1_dx] cannot be represented. +typedef char i8a1_d_t[DIFF_MAX]; +*/ + +typedef char i8a1_d_p1_t[(size_t)DIFF_MAX + 1]; /* { dg-error "size .\[0-9\]+. of array .i8a1_d_p1_t. exceeds maximum object size .\[0-9\]+.|is too large" } */ + +typedef char i8a1_s_t[SIZE_MAX]; /* { dg-error "size .\[0-9\]+. of array .i8a1_s_t. exceeds maximum object size .\[0-9\]+.|is too large" } */ + +typedef int16_t i16a_s_d2_t[SIZE_MAX / 2]; /* { dg-error "size .\[0-9\]+. of array .i16a_s_d2_t. exceeds maximum object size .\[0-9\]+." } */ +typedef int16_t i16a_s_d3_t[SIZE_MAX / 3]; /* { dg-error "size .\[0-9\]+. of array .i16a_s_d3_t. exceeds maximum object size .\[0-9\]+." } */ +typedef int16_t i16a_s_d4_m1_t[SIZE_MAX / 4 - 1]; +typedef int16_t i16a_s_d4_p1_t[SIZE_MAX / 4 + 1]; /* { dg-error "size .\[0-9\]+. of array .i16a_s_d4_p1_t. exceeds maximum object size .\[0-9\]+." } */ + +/* The internal computation overflows the message doesn't show the object + size (but GCC should compute the result and print it anyway). */ +typedef int32_t i32a_s_d2_t[SIZE_MAX / 2]; /* { dg-error "size of array .i32a_s_d2_t. exceeds maximum object size .\[0-9\]+." } */ +typedef int32_t i32a_s_d3_t[SIZE_MAX / 3]; /* { dg-error "size of array .i32a_s_d3_t. exceeds maximum object size .\[0-9\]+." } */ +typedef int32_t i32a_s_d4_t[SIZE_MAX / 4]; /* { dg-error "size .\[0-9\]+. of array .i32a_s_d4_t. exceeds maximum object size .\[0-9\]+." } */ + + +/* Verify errors for objects. */ + +char i8a1_d_m1[DIFF_MAX - 1]; +/* The following should also be diagnosed because the difference between + &i8a1_dx[0] and &i8a1_dx[sizeof i8a1_dx] cannot be represented. +char i8a1_d[DIFF_MAX]; +*/ + +char i8a_d_p1[(size_t)DIFF_MAX + 1]; /* { dg-error "size .\[0-9\]+. of array .i8a_d_p1. exceeds maximum object size .\[0-9\]+.|is too large" } */ + +char i8a_s[SIZE_MAX]; /* { dg-error "size .\[0-9\]+. of array .i8a_s. exceeds maximum object size .\[0-9\]+.|is too large" } */ + +int16_t i16a_s_d2[SIZE_MAX / 2]; /* { dg-error "size .\[0-9\]+. of array .i16a_s_d2. exceeds maximum object size .\[0-9\]+." } */ +int16_t i16a_s_d3[SIZE_MAX / 3]; /* { dg-error "size .\[0-9\]+. of array .i16a_s_d3. exceeds maximum object size .\[0-9\]+." } */ +int16_t i16a_sz_d4_m1[SIZE_MAX / 4 - 1]; +int16_t i16a_sz_d4_p1[SIZE_MAX / 4 + 1]; /* { dg-error "size .\[0-9\]+. of array .i16a_sz_d4_p1. exceeds maximum object size .\[0-9\]+." } */ + +/* The internal computation overflows the message doesn't show the object + size (but GCC should compute the result and print it anyway). */ +int32_t i32a_s_d2[SIZE_MAX / 2]; /* { dg-error "size of array .i32a_s_d2. exceeds maximum object size .\[0-9\]+." } */ +int32_t i32a_s_d3[SIZE_MAX / 3]; /* { dg-error "size of array .i32a_s_d3. exceeds maximum object size .\[0-9\]+." } */ +int32_t i32a_s_d4[SIZE_MAX / 4]; /* { dg-error "size .\[0-9\]+. of array .i32a_s_d4. exceeds maximum object size .\[0-9\]+." } */ diff --git a/gcc/testsuite/c-c++-common/pr68107.c b/gcc/testsuite/c-c++-common/pr68107.c index f1ed465e078..6cf19cb0da9 100644 --- a/gcc/testsuite/c-c++-common/pr68107.c +++ b/gcc/testsuite/c-c++-common/pr68107.c @@ -3,35 +3,35 @@ #define N ((__SIZE_MAX__ / sizeof (int)) / 2 + 1) -typedef int (*T1)[N]; /* { dg-error "too large" } */ +typedef int (*T1)[N]; /* { dg-error "exceeds maximum object size" } */ typedef int (*T2)[N - 1]; -typedef int (*T3)[N][N]; /* { dg-error "too large" } */ -typedef int (*T4)[N - 1][N - 1]; /* { dg-error "too large" } */ -typedef int (**T5)[N]; /* { dg-error "too large" } */ +typedef int (*T3)[N][N]; /* { dg-error "exceeds maximum object size" } */ +typedef int (*T4)[N - 1][N - 1]; /* { dg-error "exceeds maximum object size" } */ +typedef int (**T5)[N]; /* { dg-error "exceeds maximum object size" } */ struct S { - int (*q1)[N]; /* { dg-error "too large" } */ + int (*q1)[N]; /* { dg-error "exceeds maximum object size" } */ int (*q2)[N - 1]; - int (*q3)[N][N]; /* { dg-error "too large" } */ - int (*q4)[N - 1][N - 1]; /* { dg-error "too large" } */ - int (**q5)[N]; /* { dg-error "too large" } */ + int (*q3)[N][N]; /* { dg-error "exceeds maximum object size" } */ + int (*q4)[N - 1][N - 1]; /* { dg-error "exceeds maximum object size" } */ + int (**q5)[N]; /* { dg-error "exceeds maximum object size" } */ }; -void fn1 (int (*p1)[N]); /* { dg-error "too large" } */ +void fn1 (int (*p1)[N]); /* { dg-error "exceeds maximum object size" } */ void fn2 (int (*p1)[N - 1]); -void fn3 (int (*p3)[N][N]); /* { dg-error "too large" } */ -void fn4 (int (*p4)[N - 1][N - 1]); /* { dg-error "too large" } */ -void fn5 (int (**p5)[N]); /* { dg-error "too large" } */ +void fn3 (int (*p3)[N][N]); /* { dg-error "exceeds maximum object size" } */ +void fn4 (int (*p4)[N - 1][N - 1]); /* { dg-error "exceeds maximum object size" } */ +void fn5 (int (**p5)[N]); /* { dg-error "exceeds maximum object size" } */ void fn (void) { - int (*n1)[N]; /* { dg-error "too large" } */ + int (*n1)[N]; /* { dg-error "exceeds maximum object size" } */ int (*n2)[N - 1]; - int (*n3)[N][N]; /* { dg-error "too large" } */ - int (*n4)[N - 1][N - 1]; /* { dg-error "too large" } */ - int (**n5)[N]; /* { dg-error "too large" } */ + int (*n3)[N][N]; /* { dg-error "exceeds maximum object size" } */ + int (*n4)[N - 1][N - 1]; /* { dg-error "exceeds maximum object size" } */ + int (**n5)[N]; /* { dg-error "exceeds maximum object size" } */ - sizeof (int (*)[N]); /* { dg-error "too large" } */ - sizeof (int [N]); /* { dg-error "too large" } */ + sizeof (int (*)[N]); /* { dg-error "exceeds maximum object size" } */ + sizeof (int [N]); /* { dg-error "exceeds maximum object size" } */ } diff --git a/gcc/testsuite/g++.dg/init/new38.C b/gcc/testsuite/g++.dg/init/new38.C index a03e231cbfe..cf73aa18e60 100644 --- a/gcc/testsuite/g++.dg/init/new38.C +++ b/gcc/testsuite/g++.dg/init/new38.C @@ -5,7 +5,7 @@ large_array_char(int n) { new char[n] [1ULL << (sizeof(void *) * 4)] - [1ULL << (sizeof(void *) * 4)]; // { dg-error "size of unnamed array" } + [1ULL << (sizeof(void *) * 4)]; // { dg-error "size of array" } } template @@ -14,7 +14,7 @@ large_array_char_template(int n) { new char[n] [1ULL << (sizeof(void *) * 4)] - [1ULL << (sizeof(void *) * 4)]; // { dg-error "size of unnamed array" } + [1ULL << (sizeof(void *) * 4)]; // { dg-error "size of array" } } @@ -22,7 +22,7 @@ template void large_array_template1(int n) { - new T[n] // { dg-error "size of unnamed array is too large" } + new T[n] // { dg-error "size of array exceeds maximum object size" } [(1ULL << (sizeof(void *) * 4)) / sizeof(T)] [1ULL << (sizeof(void *) * 4)]; } @@ -31,7 +31,7 @@ template void large_array_template2(int n) { - new T[n] // { dg-error "size of unnamed array is too large" } + new T[n] // { dg-error "size of array exceeds maximum object size" } [(1ULL << (sizeof(void *) * 4)) / sizeof(T)] [1ULL << (sizeof(void *) * 4)]; } @@ -40,7 +40,7 @@ template void large_array_template3(int n) { - new T[n] // { dg-error "size of unnamed array is too large" } + new T[n] // { dg-error "size of array exceeds maximum object size" } [(1ULL << (sizeof(void *) * 4)) / sizeof(T)] [1ULL << (sizeof(void *) * 4)]; } diff --git a/gcc/testsuite/g++.dg/init/new43.C b/gcc/testsuite/g++.dg/init/new43.C index aa40b429469..e2ad67d8307 100644 --- a/gcc/testsuite/g++.dg/init/new43.C +++ b/gcc/testsuite/g++.dg/init/new43.C @@ -30,36 +30,36 @@ void test_literal () B b; // Verify integer literal. - p = new char [-1]; // { dg-error "size of array is negative" } - p = new char [2][-3]; // { dg-error "size of array|narrowing conversion" } - p = new char [-4][5]; // { dg-error "size of array is negative" } - p = new char [-6][-7]; // { dg-error "size of array|narrowing conversion" } - - p = new (p) char [-1]; // { dg-error "size of array is negative" } - p = new (p) char [2][-3]; // { dg-error "size of array|narrowing conversion" } - p = new (p) char [-4][5]; // { dg-error "size of array is negative" } - p = new (p) char [-6][-7]; // { dg-error "size of array|narrowing conversion" } - - p = new (p) A [-1]; // { dg-error "size of array is negative" } - p = new (p) A [2][-3]; // { dg-error "size of array|narrowing conversion" } - p = new (p) A [-4][5]; // { dg-error "size of array is negative" } - p = new (p) A [-6][-7]; // { dg-error "size of array|narrowing conversion" } - - p = new (p) B [-1]; // { dg-error "size of array is negative" } - p = new (p) B [2][-3]; // { dg-error "size of array|narrowing conversion" } - p = new (p) B [-4][5]; // { dg-error "size of array is negative" } - p = new (p) B [-6][-7]; // { dg-error "size of array|narrowing conversion" } - - p = new (&b) B [-1]; // { dg-error "size of array is negative" } - p = new (&b) B [2][-3]; // { dg-error "size of array|narrowing conversion" } - p = new (&b) B [-4][5]; // { dg-error "size of array is negative" } - p = new (&b) B [-6][-7]; // { dg-error "size of array|narrowing conversion" } - - p = new char [1 - 2]; // { dg-error "size of array is negative" } - p = new (p) char [2 - 3]; // { dg-error "size of array is negative" } - p = new A [2 < 1 ? -1 : -2]; // { dg-error "size of array is negative" } - p = new (p) B [2 - 3 * 2]; // { dg-error "size of array is negative" } - p = new (&b) B [1][2 - 3 * 2];// { dg-error "size of array|narrowing conversion" } + p = new char [-1]; // { dg-error "size .-1. of array is negative" } + p = new char [2][-3]; // { dg-error "size .-3. of array|narrowing conversion" } + p = new char [-4][5]; // { dg-error "size .-4. of array is negative" } + p = new char [-6][-7]; // { dg-error "size .-\[67\]. of array|narrowing conversion" } + + p = new (p) char [-1]; // { dg-error "size .-1. of array is negative" } + p = new (p) char [2][-3]; // { dg-error "size .-3. of array|narrowing conversion" } + p = new (p) char [-4][5]; // { dg-error "size .-4. of array is negative" } + p = new (p) char [-6][-7]; // { dg-error "size .-\[67\]. of array|narrowing conversion" } + + p = new (p) A [-1]; // { dg-error "size .-1. of array is negative" } + p = new (p) A [2][-3]; // { dg-error "size .-3. of array|narrowing conversion" } + p = new (p) A [-4][5]; // { dg-error "size .-4. of array is negative" } + p = new (p) A [-6][-7]; // { dg-error "size .-\[67\]. of array|narrowing conversion" } + + p = new (p) B [-1]; // { dg-error "size .-1. of array is negative" } + p = new (p) B [2][-3]; // { dg-error "size .-3. of array|narrowing conversion" } + p = new (p) B [-4][5]; // { dg-error "size .-4. of array is negative" } + p = new (p) B [-6][-7]; // { dg-error "size .-\[67\]. of array|narrowing conversion" } + + p = new (&b) B [-1]; // { dg-error "size .-1. of array is negative" } + p = new (&b) B [2][-3]; // { dg-error "size .-3. of array|narrowing conversion" } + p = new (&b) B [-4][5]; // { dg-error "size .-4. of array is negative" } + p = new (&b) B [-6][-7]; // { dg-error "size .-\[67\]. of array|narrowing conversion" } + + p = new char [1 - 2]; // { dg-error "size .-1. of array is negative" } + p = new (p) char [2 - 3]; // { dg-error "size .-1. of array is negative" } + p = new A [2 < 1 ? -1 : -2]; // { dg-error "size .-2. of array is negative" } + p = new (p) B [2 - 3 * 2]; // { dg-error "size .-4. of array is negative" } + p = new (&b) B [1][2 - 3 * 2];// { dg-error "size .-4. of array|narrowing conversion" } } void test_constant_expression () @@ -78,36 +78,36 @@ void test_constant_expression () static const int i7 = -7; // Verify constant expression. - p = new char [i1]; // { dg-error "size of array is negative" } - p = new char [2][i3]; // { dg-error "size of array|narrowing conversion" } - p = new char [i4][5]; // { dg-error "size of array is negative" } - p = new char [i6][i7]; // { dg-error "size of array|narrowing conversion" } - - p = new (p) char [i1]; // { dg-error "size of array is negative" } - p = new (p) char [2][i3]; // { dg-error "size of array|narrowing conversion" } - p = new (p) char [i4][5]; // { dg-error "size of array is negative" } - p = new (p) char [i6][i7]; // { dg-error "size of array|narrowing conversion" } - - p = new (p) A [i1]; // { dg-error "size of array is negative" } - p = new (p) A [2][i3]; // { dg-error "size of array|narrowing conversion" } - p = new (p) A [i4][5]; // { dg-error "size of array is negative" } - p = new (p) A [i6][i7]; // { dg-error "size of array|narrowing conversion" } - - p = new (p) B [i1]; // { dg-error "size of array is negative" } - p = new (p) B [2][i3]; // { dg-error "size of array|narrowing conversion" } - p = new (p) B [i4][5]; // { dg-error "size of array is negative" } - p = new (p) B [i6][i7]; // { dg-error "size of array|narrowing conversion" } - - p = new (&b) B [i1]; // { dg-error "size of array is negative" } - p = new (&b) B [2][i3]; // { dg-error "size of array|narrowing conversion" } - p = new (&b) B [i4][5]; // { dg-error "size of array is negative" } - p = new (&b) B [i6][i7]; // { dg-error "size of array|narrowing conversion" } - - p = new short [i1 - 2]; // { dg-error "size of array is negative" } - p = new (p) bool [i2 - 3]; // { dg-error "size of array is negative" } - p = new A [2 < 1 ? i1 : i2]; // { dg-error "size of array is negative" } - p = new (p) B [2 + i3 * 2]; // { dg-error "size of array is negative" } - p = new (&b) B [1][i1 - 3 * 2];// { dg-error "size of array|narrowing conversion" } + p = new char [i1]; // { dg-error "size .-1. of array is negative" } + p = new char [2][i3]; // { dg-error "size .-3. of array|narrowing conversion" } + p = new char [i4][5]; // { dg-error "size .-4. of array is negative" } + p = new char [i6][i7]; // { dg-error "size .-\[67\]. of array|narrowing conversion" } + + p = new (p) char [i1]; // { dg-error "size .-1. of array is negative" } + p = new (p) char [2][i3]; // { dg-error "size .-3. of array|narrowing conversion" } + p = new (p) char [i4][5]; // { dg-error "size .-4. of array is negative" } + p = new (p) char [i6][i7]; // { dg-error "size .-\[67\]. of array|narrowing conversion" } + + p = new (p) A [i1]; // { dg-error "size .-1. of array is negative" } + p = new (p) A [2][i3]; // { dg-error "size .-3. of array|narrowing conversion" } + p = new (p) A [i4][5]; // { dg-error "size .-4. of array is negative" } + p = new (p) A [i6][i7]; // { dg-error "size .-\[67\]. of array|narrowing conversion" } + + p = new (p) B [i1]; // { dg-error "size .-1. of array is negative" } + p = new (p) B [2][i3]; // { dg-error "size .-3. of array|narrowing conversion" } + p = new (p) B [i4][5]; // { dg-error "size .-4. of array is negative" } + p = new (p) B [i6][i7]; // { dg-error "size .-\[67\]. of array|narrowing conversion" } + + p = new (&b) B [i1]; // { dg-error "size .-1. of array is negative" } + p = new (&b) B [2][i3]; // { dg-error "size .-3. of array|narrowing conversion" } + p = new (&b) B [i4][5]; // { dg-error "size .-4. of array is negative" } + p = new (&b) B [i6][i7]; // { dg-error "size .-\[67\]. of array|narrowing conversion" } + + p = new short [i1 - 2]; // { dg-error "size .-3. of array is negative" } + p = new (p) bool [i2 - 3]; // { dg-error "size .-5. of array is negative" } + p = new A [2 < 1 ? i1 : i2]; // { dg-error "size .-2. of array is negative" } + p = new (p) B [2 + i3 * 2]; // { dg-error "size .-4. of array is negative" } + p = new (&b) B [1][i1 - 3 * 2];// { dg-error "size .-7. of array|narrowing conversion" } } void test_constexpr () @@ -131,34 +131,37 @@ void test_constexpr () #endif // Verify constant expression. - p = new char [s1]; // { dg-error "size of array is negative" } - p = new char [2][s3]; // { dg-error "size of array|narrowing conversion" } - p = new char [s4][5]; // { dg-error "size of array is negative" } - p = new char [s6][s7]; // { dg-error "size of array|narrowing conversion" } - - p = new (p) char [s1]; // { dg-error "size of array is negative" } - p = new (p) char [2][s3]; // { dg-error "size of array|narrowing conversion" } - p = new (p) char [s4][5]; // { dg-error "size of array is negative" } - p = new (p) char [s6][s7]; // { dg-error "size of array|narrowing conversion" } - - p = new (p) A [s1]; // { dg-error "size of array is negative" } - p = new (p) A [2][s3]; // { dg-error "size of array|narrowing conversion" } - p = new (p) A [s4][5]; // { dg-error "size of array is negative" } - p = new (p) A [s6][s7]; // { dg-error "size of array|narrowing conversion" } - - p = new (p) B [s1]; // { dg-error "size of array is negative" } - p = new (p) B [2][s3]; // { dg-error "size of array|narrowing conversion" } - p = new (p) B [s4][5]; // { dg-error "size of array is negative" } - p = new (p) B [s6][s7]; // { dg-error "size of array|narrowing conversion" } - - p = new (&b) B [s1]; // { dg-error "size of array is negative" } - p = new (&b) B [2][s3]; // { dg-error "size of array|narrowing conversion" } - p = new (&b) B [s4][5]; // { dg-error "size of array is negative" } - p = new (&b) B [s6][s7]; // { dg-error "size of array|narrowing conversion" } - - p = new int [s1 + s2]; // { dg-error "size of array is negative" } - p = new (p) long [2 * s3]; // { dg-error "size of array is negative" } - p = new A [s2 < s1 ? s1 : s2]; // { dg-error "size of array is negative" } - p = new (p) B [s7 - s2 * 2]; // { dg-error "size of array is negative" } - p = new (&b) B [9][s4 - s1 * 2]; // { dg-error "size of array|narrowing conversion" } + p = new char [s1]; // { dg-error "size .-1. of array is negative" } + p = new char [2][s3]; // { dg-error "size .-3. of array|narrowing conversion" } + p = new char [s4][5]; // { dg-error "size .-4. of array is negative" } + p = new char [s6][s7]; // { dg-error "size .-\[67\]. of array|narrowing conversion" } + + p = new (p) char [s1]; // { dg-error "size .-1. of array is negative" } + p = new (p) char [2][s3]; // { dg-error "size .-3. of array|narrowing conversion" } + p = new (p) char [s4][5]; // { dg-error "size .-4. of array is negative" } + p = new (p) char [s6][s7]; // { dg-error "size .-\[67\]. of array|narrowing conversion" } + + p = new (p) A [s1]; // { dg-error "size .-1. of array is negative" } + p = new (p) A [2][s3]; // { dg-error "size .-3. of array|narrowing conversion" } + p = new (p) A [s4][5]; // { dg-error "size .-4. of array is negative" } + p = new (p) A [s6][s7]; // { dg-error "size .-\[67\]. of array|narrowing conversion" } + + p = new (p) B [s1]; // { dg-error "size .-1. of array is negative" } + p = new (p) B [2][s3]; // { dg-error "size .-3. of array|narrowing conversion" } + p = new (p) B [s4][5]; // { dg-error "size .-4. of array is negative" } + p = new (p) B [s6][s7]; // { dg-error "size .-\[67\]. of array|narrowing conversion" } + + p = new (&b) B [s1]; // { dg-error "size .-1. of array is negative" } + p = new (&b) B [2][s3]; // { dg-error "size .-3. of array|narrowing conversion" } + p = new (&b) B [s4][5]; // { dg-error "size .-4. of array is negative" } + p = new (&b) B [s6][s7]; // { dg-error "size .-\[67\]. of array|narrowing conversion" } + + p = new int [s1 + s2]; // { dg-error "size .-3. of array is negative" } + p = new (p) long [2 * s3]; // { dg-error "size .-6. of array is negative" } + p = new A [s2 < s1 ? s1 : s2]; // { dg-error "size .-1. of array is negative" } + p = new (p) B [s7 - s2 * 2]; // { dg-error "size .-3. of array is negative" } + p = new (&b) B [9][s4 - s1 * 2]; // { dg-error "size .-2. of array|narrowing conversion" } } + +/* Prune out pedantic warnins (turned into errors via -pedantic-errors). + { dg-prune-output "size of array is not an integral constant-expressio" } */ diff --git a/gcc/testsuite/g++.dg/init/new44.C b/gcc/testsuite/g++.dg/init/new44.C index 5c81c2c746b..a10ef424136 100644 --- a/gcc/testsuite/g++.dg/init/new44.C +++ b/gcc/testsuite/g++.dg/init/new44.C @@ -37,13 +37,13 @@ void *p; static void __attribute__ ((used)) test_one_dim_char_array () { - p = new char [MAX]; // { dg-error "size of array" } - p = new char [MAX - 1]; // { dg-error "size of array" } - p = new char [MAX - 2]; // { dg-error "size of array" } - p = new char [MAX - 99]; // { dg-error "size of array" } - p = new char [MAX / 2]; // { dg-error "size of array" } - p = new char [MAX / 2 - 1]; // { dg-error "size of array" } - p = new char [MAX / 2 - 2]; // { dg-error "size of array" } + p = new char [MAX]; // { dg-error "size .\[0-9\]+. of array" } + p = new char [MAX - 1]; // { dg-error "size .\[0-9\]+. of array" } + p = new char [MAX - 2]; // { dg-error "size .\[0-9\]+. of array" } + p = new char [MAX - 99]; // { dg-error "size .\[0-9\]+. of array" } + p = new char [MAX / 2]; // { dg-error "size .\[0-9\]+. of array" } + p = new char [MAX / 2 - 1]; // { dg-error "size .\[0-9\]+. of array" } + p = new char [MAX / 2 - 2]; // { dg-error "size .\[0-9\]+. of array" } // Avoid testing the expressions below since whether or not they // are accepted depends on the precision of size_t (which also @@ -63,20 +63,20 @@ test_one_dim_char_array () static void __attribute__ ((used)) test_one_dim_short_array () { - p = new short [MAX]; // { dg-error "size of array" } - p = new short [MAX - 1]; // { dg-error "size of array" } - p = new short [MAX - 2]; // { dg-error "size of array" } - p = new short [MAX - 99]; // { dg-error "size of array" } - p = new short [MAX / 2]; // { dg-error "size of array" } - p = new short [MAX / 2 - 1]; // { dg-error "size of array" } - p = new short [MAX / 2 - 2]; // { dg-error "size of array" } - p = new short [MAX / 2 - 3]; // { dg-error "size of array" } - p = new short [MAX / 2 - 4]; // { dg-error "size of array" } - p = new short [MAX / 2 - 5]; // { dg-error "size of array" } - p = new short [MAX / 2 - 6]; // { dg-error "size of array" } - p = new short [MAX / 2 - 7]; // { dg-error "size of array" } - p = new short [MAX / 2 - 8]; // { dg-error "size of array" } - p = new short [MAX / 4]; // { dg-error "size of array" } + p = new short [MAX]; // { dg-error "size .\[0-9\]+. of array" } + p = new short [MAX - 1]; // { dg-error "size .\[0-9\]+. of array" } + p = new short [MAX - 2]; // { dg-error "size .\[0-9\]+. of array" } + p = new short [MAX - 99]; // { dg-error "size .\[0-9\]+. of array" } + p = new short [MAX / 2]; // { dg-error "size .\[0-9\]+. of array" } + p = new short [MAX / 2 - 1]; // { dg-error "size .\[0-9\]+. of array" } + p = new short [MAX / 2 - 2]; // { dg-error "size .\[0-9\]+. of array" } + p = new short [MAX / 2 - 3]; // { dg-error "size .\[0-9\]+. of array" } + p = new short [MAX / 2 - 4]; // { dg-error "size .\[0-9\]+. of array" } + p = new short [MAX / 2 - 5]; // { dg-error "size .\[0-9\]+. of array" } + p = new short [MAX / 2 - 6]; // { dg-error "size .\[0-9\]+. of array" } + p = new short [MAX / 2 - 7]; // { dg-error "size .\[0-9\]+. of array" } + p = new short [MAX / 2 - 8]; // { dg-error "size .\[0-9\]+. of array" } + p = new short [MAX / 4]; // { dg-error "size .\[0-9\]+. of array" } // Avoid exercising data model-dependent expressions. // p = new short [MAX / 4 - 1]; @@ -88,13 +88,13 @@ 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 / 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" } + p = new char [1][MAX]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new char [1][MAX - 1]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new char [1][MAX - 2]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new char [1][MAX - 99]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new char [1][MAX / 2]; // { dg-error "size .\[0-9\]+. of array" } + p = new char [1][MAX / 2 - 1]; // { dg-error "size .\[0-9\]+. of array" } + p = new char [1][MAX / 2 - 2]; // { dg-error "size .\[0-9\]+. of array" } // Avoid exercising data model-dependent expressions. // p = new char [1][MAX / 2 - 3]; @@ -105,28 +105,28 @@ 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 / 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 / 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" } - p = new char [MAX][MAX / 2 - 7]; // { dg-error "size of array" } - p = new char [MAX][MAX / 2 - 8]; // { dg-error "size of array" } - p = new char [MAX][2]; // { dg-error "size of array" } - p = new char [MAX][1]; // { dg-error "size of array" } - p = new char [MAX / 2][1]; // { dg-error "size of array" } - p = new char [MAX / 2 - 1][1]; // { dg-error "size of array" } - p = new char [MAX / 2 - 2][1]; // { dg-error "size of array" } + p = new char [2][MAX]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new char [2][MAX - 1]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new char [2][MAX - 2]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new char [2][MAX / 2]; // { dg-error "size .\[0-9\]+. of array" } + p = new char [2][MAX / 2 - 1]; // { dg-error "size .\[0-9\]+. of array" } + p = new char [2][MAX / 2 - 2]; // { dg-error "size .\[0-9\]+. of array" } + p = new char [2][MAX / 2 - 7]; // { dg-error "size .\[0-9\]+. of array" } + p = new char [2][MAX / 2 - 8]; // { dg-error "size .\[0-9\]+. of array" } + + p = new char [MAX][MAX]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new char [MAX][MAX - 1]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new char [MAX][MAX - 2]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new char [MAX][MAX / 2]; // { dg-error "size .\[0-9\]+. of array" } + p = new char [MAX][MAX / 2 - 1]; // { dg-error "size .\[0-9\]+. of array" } + p = new char [MAX][MAX / 2 - 2]; // { dg-error "size .\[0-9\]+. of array" } + p = new char [MAX][MAX / 2 - 7]; // { dg-error "size .\[0-9\]+. of array" } + p = new char [MAX][MAX / 2 - 8]; // { dg-error "size .\[0-9\]+. of array" } + p = new char [MAX][2]; // { dg-error "size .\[0-9\]+. of array" } + p = new char [MAX][1]; // { dg-error "size .\[0-9\]+. of array" } + p = new char [MAX / 2][1]; // { dg-error "size .\[0-9\]+. of array" } + p = new char [MAX / 2 - 1][1]; // { dg-error "size .\[0-9\]+. of array" } + p = new char [MAX / 2 - 2][1]; // { dg-error "size .\[0-9\]+. of array" } // Avoid exercising data model-dependent expressions. // p = new char [MAX / 2 - 3][1]; @@ -143,13 +143,13 @@ 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 / 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" } + p = new char [1][1][MAX]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new char [1][1][MAX - 1]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new char [1][1][MAX - 2]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new char [1][1][MAX - 99]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new char [1][1][MAX / 2]; // { dg-error "size .\[0-9\]+. of array" } + p = new char [1][1][MAX / 2 - 1]; // { dg-error "size .\[0-9\]+. of array" } + p = new char [1][1][MAX / 2 - 2]; // { dg-error "size .\[0-9\]+. of array" } // Avoid exercising data model-dependent expressions. // p = new char [1][1][MAX / 2 - 3]; @@ -160,20 +160,20 @@ 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 / 4]; // { dg-error "size of array" } + p = new char [1][2][MAX]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new char [1][2][MAX - 1]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new char [1][2][MAX - 2]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new char [1][2][MAX - 99]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new char [1][2][MAX / 2]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new char [1][2][MAX / 2 - 1]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new char [1][2][MAX / 2 - 2]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new char [1][2][MAX / 2 - 3]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new char [1][2][MAX / 2 - 4]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new char [1][2][MAX / 2 - 5]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new char [1][2][MAX / 2 - 6]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new char [1][2][MAX / 2 - 7]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new char [1][2][MAX / 2 - 8]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new char [1][2][MAX / 4]; // { dg-error "size .\[0-9\]+. of array" } // Avoid exercising data model-dependent expressions. // p = new char [1][2][MAX / 4 - 1]; @@ -182,20 +182,20 @@ 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 / 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" } - p = new char [2][1][MAX / 2 - 3]; // { dg-error "size of array" } - p = new char [2][1][MAX / 2 - 4]; // { dg-error "size of array" } - p = new char [2][1][MAX / 2 - 5]; // { dg-error "size of array" } - p = new char [2][1][MAX / 2 - 6]; // { dg-error "size of array" } - p = new char [2][1][MAX / 2 - 7]; // { dg-error "size of array" } - p = new char [2][1][MAX / 2 - 8]; // { dg-error "size of array" } - p = new char [2][1][MAX / 4]; // { dg-error "size of array" } + p = new char [2][1][MAX]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new char [2][1][MAX - 1]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new char [2][1][MAX - 2]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new char [2][1][MAX - 99]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new char [2][1][MAX / 2]; // { dg-error "size .\[0-9\]+. of array" } + p = new char [2][1][MAX / 2 - 1]; // { dg-error "size .\[0-9\]+. of array" } + p = new char [2][1][MAX / 2 - 2]; // { dg-error "size .\[0-9\]+. of array" } + p = new char [2][1][MAX / 2 - 3]; // { dg-error "size .\[0-9\]+. of array" } + p = new char [2][1][MAX / 2 - 4]; // { dg-error "size .\[0-9\]+. of array" } + p = new char [2][1][MAX / 2 - 5]; // { dg-error "size .\[0-9\]+. of array" } + p = new char [2][1][MAX / 2 - 6]; // { dg-error "size .\[0-9\]+. of array" } + p = new char [2][1][MAX / 2 - 7]; // { dg-error "size .\[0-9\]+. of array" } + p = new char [2][1][MAX / 2 - 8]; // { dg-error "size .\[0-9\]+. of array" } + p = new char [2][1][MAX / 4]; // { dg-error "size .\[0-9\]+. of array" } // Avoid exercising data model-dependent expressions. // p = new char [2][1][MAX / 4 - 1]; @@ -204,22 +204,22 @@ 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 / 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" } + p = new char [2][2][MAX]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new char [2][2][MAX - 1]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new char [2][2][MAX - 2]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new char [2][2][MAX - 99]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new char [2][2][MAX / 2]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new char [2][2][MAX / 2 - 1]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new char [2][2][MAX / 2 - 2]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new char [2][2][MAX / 2 - 3]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new char [2][2][MAX / 2 - 4]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new char [2][2][MAX / 2 - 5]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new char [2][2][MAX / 2 - 6]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new char [2][2][MAX / 2 - 7]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new char [2][2][MAX / 2 - 8]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new char [2][2][MAX / 4]; // { dg-error "size .\[0-9\]+. of array" } + p = new char [2][2][MAX / 4 - 1]; // { dg-error "size .\[0-9\]+. of array" } + p = new char [2][2][MAX / 4 - 2]; // { dg-error "size .\[0-9\]+. of array" } // Avoid exercising data model-dependent expressions. // p = new char [2][2][MAX / 8]; @@ -228,22 +228,22 @@ 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 / 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" } + p = new char [2][MAX][2]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new char [2][MAX - 1][2]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new char [2][MAX - 2][2]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new char [2][MAX - 99][2]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new char [2][MAX / 2][2]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new char [2][MAX / 2 - 1][2]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new char [2][MAX / 2 - 2][2]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new char [2][MAX / 2 - 3][2]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new char [2][MAX / 2 - 4][2]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new char [2][MAX / 2 - 5][2]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new char [2][MAX / 2 - 6][2]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new char [2][MAX / 2 - 7][2]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new char [2][MAX / 2 - 8][2]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new char [2][MAX / 4][2]; // { dg-error "size .\[0-9\]+. of array" } + p = new char [2][MAX / 4 - 1][2]; // { dg-error "size .\[0-9\]+. of array" } + p = new char [2][MAX / 4 - 2][2]; // { dg-error "size .\[0-9\]+. of array" } // Avoid exercising data model-dependent expressions. // p = new char [2][MAX / 8][2]; @@ -252,22 +252,22 @@ test_three_dim_char_array () p = new char [2][MAX / 8 - 2][2]; p = new char [2][MAX / 8 - 3][2]; - p = new char [MAX][2][2]; // { dg-error "size of array" } - p = new char [MAX - 1][2][2]; // { dg-error "size of array" } - p = new char [MAX - 2][2][2]; // { dg-error "size of array" } - p = new char [MAX - 99][2][2]; // { dg-error "size of array" } - p = new char [MAX / 2][2][2]; // { dg-error "size of array" } - p = new char [MAX / 2 - 1][2][2]; // { dg-error "size of array" } - p = new char [MAX / 2 - 2][2][2]; // { dg-error "size of array" } - p = new char [MAX / 2 - 3][2][2]; // { dg-error "size of array" } - p = new char [MAX / 2 - 4][2][2]; // { dg-error "size of array" } - p = new char [MAX / 2 - 5][2][2]; // { dg-error "size of array" } - p = new char [MAX / 2 - 6][2][2]; // { dg-error "size of array" } - p = new char [MAX / 2 - 7][2][2]; // { dg-error "size of array" } - p = new char [MAX / 2 - 8][2][2]; // { dg-error "size of array" } - p = new char [MAX / 4][2][2]; // { dg-error "size of array" } - p = new char [MAX / 4 - 1][2][2]; // { dg-error "size of array" } - p = new char [MAX / 4 - 2][2][2]; // { dg-error "size of array" } + p = new char [MAX][2][2]; // { dg-error "size .\[0-9\]+. of array" } + p = new char [MAX - 1][2][2]; // { dg-error "size .\[0-9\]+. of array" } + p = new char [MAX - 2][2][2]; // { dg-error "size .\[0-9\]+. of array" } + p = new char [MAX - 99][2][2]; // { dg-error "size .\[0-9\]+. of array" } + p = new char [MAX / 2][2][2]; // { dg-error "size .\[0-9\]+. of array" } + p = new char [MAX / 2 - 1][2][2]; // { dg-error "size .\[0-9\]+. of array" } + p = new char [MAX / 2 - 2][2][2]; // { dg-error "size .\[0-9\]+. of array" } + p = new char [MAX / 2 - 3][2][2]; // { dg-error "size .\[0-9\]+. of array" } + p = new char [MAX / 2 - 4][2][2]; // { dg-error "size .\[0-9\]+. of array" } + p = new char [MAX / 2 - 5][2][2]; // { dg-error "size .\[0-9\]+. of array" } + p = new char [MAX / 2 - 6][2][2]; // { dg-error "size .\[0-9\]+. of array" } + p = new char [MAX / 2 - 7][2][2]; // { dg-error "size .\[0-9\]+. of array" } + p = new char [MAX / 2 - 8][2][2]; // { dg-error "size .\[0-9\]+. of array" } + p = new char [MAX / 4][2][2]; // { dg-error "size .\[0-9\]+. of array" } + p = new char [MAX / 4 - 1][2][2]; // { dg-error "size .\[0-9\]+. of array" } + p = new char [MAX / 4 - 2][2][2]; // { dg-error "size .\[0-9\]+. of array" } // Avoid exercising data model-dependent expressions. // p = new char [MAX / 8][2][2]; @@ -276,9 +276,9 @@ 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][MAX]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new char [MAX][MAX][MAX / 2]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new char [MAX][MAX / 2][MAX]; // { dg-error "size .\[0-9\]+. 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" } } @@ -297,9 +297,9 @@ test_N_dim_char_array () p = new char [N][N][N][N][N][N][N]; p = new char [N / 2][2][N][N][N][N][N][N]; p = new char [N - 1][N / 2][N][N][N][N][N][N]; - p = new char [N / 2][N][N][N][N][N][N][N]; // { dg-error "size of array" } - p = new char [N - 1][N][N][N][N][N][N][N]; // { dg-error "size of array" } - p = new char [N] [N][N][N][N][N][N][N]; // { dg-error "size of array" } + p = new char [N / 2][N][N][N][N][N][N][N]; // { dg-error "size .\[0-9\]+. of array" } + p = new char [N - 1][N][N][N][N][N][N][N]; // { dg-error "size .\[0-9\]+. of array" } + p = new char [N] [N][N][N][N][N][N][N]; // { dg-error "size .\[0-9\]+. of array" } } typedef struct Byte { @@ -316,17 +316,17 @@ void* operator new[] (size_t, B*); static void __attribute__ ((used)) test_one_dim_byte_array (void *p) { - p = new (p) B [MAX]; // { dg-error "size of array" } - p = new (p) B [MAX - 1]; // { dg-error "size of array" } - p = new (p) B [MAX - 2]; // { dg-error "size of array" } - p = new (p) B [MAX - 99]; // { dg-error "size of array" } - p = new (p) B [MAX / 2]; // { dg-error "size of array" } - p = new (p) B [MAX / 2 - 1]; // { dg-error "size of array" } - p = new (p) B [MAX / 2 - 2]; // { dg-error "size of array" } + p = new (p) B [MAX]; // { dg-error "size .\[0-9\]+. of array" } + p = new (p) B [MAX - 1]; // { dg-error "size .\[0-9\]+. of array" } + p = new (p) B [MAX - 2]; // { dg-error "size .\[0-9\]+. of array" } + p = new (p) B [MAX - 99]; // { dg-error "size .\[0-9\]+. of array" } + p = new (p) B [MAX / 2]; // { dg-error "size .\[0-9\]+. of array" } + p = new (p) B [MAX / 2 - 1]; // { dg-error "size .\[0-9\]+. of array" } + p = new (p) B [MAX / 2 - 2]; // { dg-error "size .\[0-9\]+. of array" } // Avoid testing the expressions below since whether or not they // are accepted depends on the precision of size_t (which determines - // the size of the cookie). + // the size .\[0-9\]+. of the cookie). // p = new (p) B [MAX / 2 - 3]; // p = new (p) B [MAX / 2 - 4]; // p = new (p) B [MAX / 2 - 5]; @@ -343,13 +343,13 @@ 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 / 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" } + p = new (p) B [1][MAX]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new (p) B [1][MAX - 1]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new (p) B [1][MAX - 2]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new (p) B [1][MAX - 99]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new (p) B [1][MAX / 2]; // { dg-error "size .\[0-9\]+. of array" } + p = new (p) B [1][MAX / 2 - 1]; // { dg-error "size .\[0-9\]+. of array" } + p = new (p) B [1][MAX / 2 - 2]; // { dg-error "size .\[0-9\]+. of array" } // Avoid exercising data model-dependent expressions. // p = new (p) B [1][MAX / 2 - 3]; @@ -360,28 +360,28 @@ 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 / 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 / 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" } - p = new (p) B [MAX][MAX / 2 - 7]; // { dg-error "size of array" } - p = new (p) B [MAX][MAX / 2 - 8]; // { dg-error "size of array" } - p = new (p) B [MAX][2]; // { dg-error "size of array" } - p = new (p) B [MAX][1]; // { dg-error "size of array" } - p = new (p) B [MAX / 2][1]; // { dg-error "size of array" } - p = new (p) B [MAX / 2 - 1][1]; // { dg-error "size of array" } - p = new (p) B [MAX / 2 - 2][1]; // { dg-error "size of array" } + p = new (p) B [2][MAX]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new (p) B [2][MAX - 1]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new (p) B [2][MAX - 2]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new (p) B [2][MAX / 2]; // { dg-error "size .\[0-9\]+. of array" } + p = new (p) B [2][MAX / 2 - 1]; // { dg-error "size .\[0-9\]+. of array" } + p = new (p) B [2][MAX / 2 - 2]; // { dg-error "size .\[0-9\]+. of array" } + p = new (p) B [2][MAX / 2 - 7]; // { dg-error "size .\[0-9\]+. of array" } + p = new (p) B [2][MAX / 2 - 8]; // { dg-error "size .\[0-9\]+. of array" } + + p = new (p) B [MAX][MAX]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new (p) B [MAX][MAX - 1]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new (p) B [MAX][MAX - 2]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new (p) B [MAX][MAX / 2]; // { dg-error "size .\[0-9\]+. of array" } + p = new (p) B [MAX][MAX / 2 - 1]; // { dg-error "size .\[0-9\]+. of array" } + p = new (p) B [MAX][MAX / 2 - 2]; // { dg-error "size .\[0-9\]+. of array" } + p = new (p) B [MAX][MAX / 2 - 7]; // { dg-error "size .\[0-9\]+. of array" } + p = new (p) B [MAX][MAX / 2 - 8]; // { dg-error "size .\[0-9\]+. of array" } + p = new (p) B [MAX][2]; // { dg-error "size .\[0-9\]+. of array" } + p = new (p) B [MAX][1]; // { dg-error "size .\[0-9\]+. of array" } + p = new (p) B [MAX / 2][1]; // { dg-error "size .\[0-9\]+. of array" } + p = new (p) B [MAX / 2 - 1][1]; // { dg-error "size .\[0-9\]+. of array" } + p = new (p) B [MAX / 2 - 2][1]; // { dg-error "size .\[0-9\]+. of array" } // Avoid exercising data model-dependent expressions. // p = new (p) B [MAX / 2 - 3][1]; @@ -398,13 +398,13 @@ 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 / 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" } + p = new (p) B [1][1][MAX]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new (p) B [1][1][MAX - 1]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new (p) B [1][1][MAX - 2]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new (p) B [1][1][MAX - 99]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new (p) B [1][1][MAX / 2]; // { dg-error "size .\[0-9\]+. of array" } + p = new (p) B [1][1][MAX / 2 - 1]; // { dg-error "size .\[0-9\]+. of array" } + p = new (p) B [1][1][MAX / 2 - 2]; // { dg-error "size .\[0-9\]+. of array" } // Avoid exercising data model-dependent expressions. // p = new (p) B [1][1][MAX / 2 - 3]; @@ -415,20 +415,20 @@ 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 / 4]; // { dg-error "size of array" } + p = new (p) B [1][2][MAX]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new (p) B [1][2][MAX - 1]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new (p) B [1][2][MAX - 2]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new (p) B [1][2][MAX - 99]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new (p) B [1][2][MAX / 2]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new (p) B [1][2][MAX / 2 - 1]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new (p) B [1][2][MAX / 2 - 2]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new (p) B [1][2][MAX / 2 - 3]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new (p) B [1][2][MAX / 2 - 4]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new (p) B [1][2][MAX / 2 - 5]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new (p) B [1][2][MAX / 2 - 6]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new (p) B [1][2][MAX / 2 - 7]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new (p) B [1][2][MAX / 2 - 8]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new (p) B [1][2][MAX / 4]; // { dg-error "size .\[0-9\]+. of array" } // Avoid exercising data model-dependent expressions. // p = new (p) B [1][2][MAX / 4 - 1]; @@ -437,20 +437,20 @@ 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 / 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" } - p = new (p) B [2][1][MAX / 2 - 3]; // { dg-error "size of array" } - p = new (p) B [2][1][MAX / 2 - 4]; // { dg-error "size of array" } - p = new (p) B [2][1][MAX / 2 - 5]; // { dg-error "size of array" } - p = new (p) B [2][1][MAX / 2 - 6]; // { dg-error "size of array" } - p = new (p) B [2][1][MAX / 2 - 7]; // { dg-error "size of array" } - p = new (p) B [2][1][MAX / 2 - 8]; // { dg-error "size of array" } - p = new (p) B [2][1][MAX / 4]; // { dg-error "size of array" } + p = new (p) B [2][1][MAX]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new (p) B [2][1][MAX - 1]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new (p) B [2][1][MAX - 2]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new (p) B [2][1][MAX - 99]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new (p) B [2][1][MAX / 2]; // { dg-error "size .\[0-9\]+. of array" } + p = new (p) B [2][1][MAX / 2 - 1]; // { dg-error "size .\[0-9\]+. of array" } + p = new (p) B [2][1][MAX / 2 - 2]; // { dg-error "size .\[0-9\]+. of array" } + p = new (p) B [2][1][MAX / 2 - 3]; // { dg-error "size .\[0-9\]+. of array" } + p = new (p) B [2][1][MAX / 2 - 4]; // { dg-error "size .\[0-9\]+. of array" } + p = new (p) B [2][1][MAX / 2 - 5]; // { dg-error "size .\[0-9\]+. of array" } + p = new (p) B [2][1][MAX / 2 - 6]; // { dg-error "size .\[0-9\]+. of array" } + p = new (p) B [2][1][MAX / 2 - 7]; // { dg-error "size .\[0-9\]+. of array" } + p = new (p) B [2][1][MAX / 2 - 8]; // { dg-error "size .\[0-9\]+. of array" } + p = new (p) B [2][1][MAX / 4]; // { dg-error "size .\[0-9\]+. of array" } // Avoid exercising data model-dependent expressions. // p = new (p) B [2][1][MAX / 4 - 1]; @@ -459,22 +459,22 @@ 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 / 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" } + p = new (p) B [2][2][MAX]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new (p) B [2][2][MAX - 1]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new (p) B [2][2][MAX - 2]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new (p) B [2][2][MAX - 99]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new (p) B [2][2][MAX / 2]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new (p) B [2][2][MAX / 2 - 1]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new (p) B [2][2][MAX / 2 - 2]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new (p) B [2][2][MAX / 2 - 3]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new (p) B [2][2][MAX / 2 - 4]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new (p) B [2][2][MAX / 2 - 5]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new (p) B [2][2][MAX / 2 - 6]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new (p) B [2][2][MAX / 2 - 7]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new (p) B [2][2][MAX / 2 - 8]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new (p) B [2][2][MAX / 4]; // { dg-error "size .\[0-9\]+. of array" } + p = new (p) B [2][2][MAX / 4 - 1]; // { dg-error "size .\[0-9\]+. of array" } + p = new (p) B [2][2][MAX / 4 - 2]; // { dg-error "size .\[0-9\]+. of array" } // Avoid exercising data model-dependent expressions. // p = new (p) B [2][2][MAX / 8]; @@ -483,22 +483,22 @@ 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 / 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" } + p = new (p) B [2][MAX][2]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new (p) B [2][MAX - 1][2]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new (p) B [2][MAX - 2][2]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new (p) B [2][MAX - 99][2]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new (p) B [2][MAX / 2][2]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new (p) B [2][MAX / 2 - 1][2]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new (p) B [2][MAX / 2 - 2][2]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new (p) B [2][MAX / 2 - 3][2]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new (p) B [2][MAX / 2 - 4][2]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new (p) B [2][MAX / 2 - 5][2]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new (p) B [2][MAX / 2 - 6][2]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new (p) B [2][MAX / 2 - 7][2]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new (p) B [2][MAX / 2 - 8][2]; // { dg-error "size .\[0-9\]+. of (unnamed )?array" } + p = new (p) B [2][MAX / 4][2]; // { dg-error "size .\[0-9\]+. of array" } + p = new (p) B [2][MAX / 4 - 1][2]; // { dg-error "size .\[0-9\]+. of array" } + p = new (p) B [2][MAX / 4 - 2][2]; // { dg-error "size .\[0-9\]+. of array" } // Avoid exercising data model-dependent expressions. // p = new (p) B [2][MAX / 8][2]; @@ -507,22 +507,22 @@ test_placement_three_dim_byte_struct_array (void *p) p = new (p) B [2][MAX / 8 - 2][2]; p = new (p) B [2][MAX / 8 - 3][2]; - p = new (p) B [MAX][2][2]; // { dg-error "size of array" } - p = new (p) B [MAX - 1][2][2]; // { dg-error "size of array" } - p = new (p) B [MAX - 2][2][2]; // { dg-error "size of array" } - p = new (p) B [MAX - 99][2][2]; // { dg-error "size of array" } - p = new (p) B [MAX / 2][2][2]; // { dg-error "size of array" } - p = new (p) B [MAX / 2 - 1][2][2]; // { dg-error "size of array" } - p = new (p) B [MAX / 2 - 2][2][2]; // { dg-error "size of array" } - p = new (p) B [MAX / 2 - 3][2][2]; // { dg-error "size of array" } - p = new (p) B [MAX / 2 - 4][2][2]; // { dg-error "size of array" } - p = new (p) B [MAX / 2 - 5][2][2]; // { dg-error "size of array" } - p = new (p) B [MAX / 2 - 6][2][2]; // { dg-error "size of array" } - p = new (p) B [MAX / 2 - 7][2][2]; // { dg-error "size of array" } - p = new (p) B [MAX / 2 - 8][2][2]; // { dg-error "size of array" } - p = new (p) B [MAX / 4][2][2]; // { dg-error "size of array" } - p = new (p) B [MAX / 4 - 1][2][2]; // { dg-error "size of array" } - p = new (p) B [MAX / 4 - 2][2][2]; // { dg-error "size of array" } + p = new (p) B [MAX][2][2]; // { dg-error "size .\[0-9\]+. of array" } + p = new (p) B [MAX - 1][2][2]; // { dg-error "size .\[0-9\]+. of array" } + p = new (p) B [MAX - 2][2][2]; // { dg-error "size .\[0-9\]+. of array" } + p = new (p) B [MAX - 99][2][2]; // { dg-error "size .\[0-9\]+. of array" } + p = new (p) B [MAX / 2][2][2]; // { dg-error "size .\[0-9\]+. of array" } + p = new (p) B [MAX / 2 - 1][2][2]; // { dg-error "size .\[0-9\]+. of array" } + p = new (p) B [MAX / 2 - 2][2][2]; // { dg-error "size .\[0-9\]+. of array" } + p = new (p) B [MAX / 2 - 3][2][2]; // { dg-error "size .\[0-9\]+. of array" } + p = new (p) B [MAX / 2 - 4][2][2]; // { dg-error "size .\[0-9\]+. of array" } + p = new (p) B [MAX / 2 - 5][2][2]; // { dg-error "size .\[0-9\]+. of array" } + p = new (p) B [MAX / 2 - 6][2][2]; // { dg-error "size .\[0-9\]+. of array" } + p = new (p) B [MAX / 2 - 7][2][2]; // { dg-error "size .\[0-9\]+. of array" } + p = new (p) B [MAX / 2 - 8][2][2]; // { dg-error "size .\[0-9\]+. of array" } + p = new (p) B [MAX / 4][2][2]; // { dg-error "size .\[0-9\]+. of array" } + p = new (p) B [MAX / 4 - 1][2][2]; // { dg-error "size .\[0-9\]+. of array" } + p = new (p) B [MAX / 4 - 2][2][2]; // { dg-error "size .\[0-9\]+. of array" } // Avoid exercising data model-dependent expressions. // p = new (p) B [MAX / 8][2][2]; diff --git a/gcc/testsuite/g++.dg/init/new46.C b/gcc/testsuite/g++.dg/init/new46.C index 9fd747e98d2..f0b3921cb34 100644 --- a/gcc/testsuite/g++.dg/init/new46.C +++ b/gcc/testsuite/g++.dg/init/new46.C @@ -37,7 +37,7 @@ char* fn2_2_x () { template char* fn2_2 () { - return new char [M][N]; // { dg-error "size of array is too large" } + return new char [M][N]; // { dg-error "size .\[0-9\]+. of array exceeds maximum object size" } } // Not instantiated (must not be diagnosed). @@ -50,7 +50,7 @@ T* fn3_x () { template T* fn3 () { const size_t a = sizeof (T); - return new T [a]; // { dg-error "size of array is too large" } + return new T [a]; // { dg-error "size .\[0-9\]+. of array exceeds maximum object size" } } diff --git a/gcc/testsuite/g++.dg/other/large-size-array.C b/gcc/testsuite/g++.dg/other/large-size-array.C index 9614fb12539..631e3a895f8 100644 --- a/gcc/testsuite/g++.dg/other/large-size-array.C +++ b/gcc/testsuite/g++.dg/other/large-size-array.C @@ -20,7 +20,7 @@ sub (int *a) int main (void) { - int a[DIM][DIM]; /* { dg-error "size of array 'a' is too large" } */ + int a[DIM][DIM]; /* { dg-error "exceeds maximum object size" } */ return sub (&a[0][0]); /* { dg-error "declared" } */ } diff --git a/gcc/testsuite/g++.dg/other/new-size-type.C b/gcc/testsuite/g++.dg/other/new-size-type.C index ad4dc102c3b..a99d747026a 100644 --- a/gcc/testsuite/g++.dg/other/new-size-type.C +++ b/gcc/testsuite/g++.dg/other/new-size-type.C @@ -5,5 +5,5 @@ const char* foo() { - return new char[~static_cast(0)];// { dg-error "size of array" } + return new char[~static_cast(0)];// { dg-error "exceeds maximum object size" } } diff --git a/gcc/testsuite/g++.dg/template/array30.C b/gcc/testsuite/g++.dg/template/array30.C index 3608c2e1233..98723ace609 100644 --- a/gcc/testsuite/g++.dg/template/array30.C +++ b/gcc/testsuite/g++.dg/template/array30.C @@ -1,7 +1,7 @@ template struct A { - int ar[I][I][I][I][I][I][I][I][I][I]; // { dg-error "too large" } + int ar[I][I][I][I][I][I][I][I][I][I]; // { dg-error "exceeds maximum object size" } }; A<66000> a; diff --git a/gcc/testsuite/g++.dg/template/array32.C b/gcc/testsuite/g++.dg/template/array32.C new file mode 100644 index 00000000000..f4467c7653c --- /dev/null +++ b/gcc/testsuite/g++.dg/template/array32.C @@ -0,0 +1,27 @@ +/* PR c++/87996 - "size of array is negative" error when SIZE_MAX/2 < sizeof(array) <= SIZE_MAX + { dg-do compile } + { dg-options "-ftrack-macro-expansion=0" } */ + +#define SIZE_MAX __SIZE_MAX__ + +typedef __SIZE_TYPE__ size_t; + +template struct Aszmax_d2 { + char a[N]; +}; +Aszmax_d2 aszmax_d2; + +template struct Aszmax_d2_p1 { + char a[N]; // { dg-error "exceeds maximum object size" } +}; +Aszmax_d2_p1 aszmax_d2_p1; + +template struct Aszmax { + char a[N]; // { dg-error "exceeds maximum object size" } +}; +Aszmax aszmax; + +template struct Aszmax_d2_szmax_d2 { + char a[M][N]; // { dg-error "exceeds maximum object size" } +}; +Aszmax_d2_szmax_d2 aszmaxd2_szmaxd2; diff --git a/gcc/testsuite/g++.dg/template/dependent-name3.C b/gcc/testsuite/g++.dg/template/dependent-name3.C index f9d14055a11..19ba9e74787 100644 --- a/gcc/testsuite/g++.dg/template/dependent-name3.C +++ b/gcc/testsuite/g++.dg/template/dependent-name3.C @@ -11,7 +11,7 @@ template struct A template struct B { int x[A::zero]; // { dg-error "zero" } - int y[A::minus_one]; // { dg-error "size of array|narrowing conversion" } + int y[A::minus_one]; // { dg-error "size .-1. of array is negative|narrowing conversion|not an integral constant-expression" } }; B<0> b; diff --git a/gcc/testsuite/g++.dg/ubsan/pr81530.C b/gcc/testsuite/g++.dg/ubsan/pr81530.C index 310ea8e3032..d3a3221615d 100644 --- a/gcc/testsuite/g++.dg/ubsan/pr81530.C +++ b/gcc/testsuite/g++.dg/ubsan/pr81530.C @@ -2,4 +2,4 @@ /* { dg-do compile } */ /* { dg-options "-fsanitize=undefined" } */ -int a[(long) 4e20]; /* { dg-error "7:size of array .a. is (too large|negative)" } */ +int a[(long) 4e20]; /* { dg-error "7:size of array .a." } */ diff --git a/gcc/testsuite/g++.old-deja/g++.brendan/array1.C b/gcc/testsuite/g++.old-deja/g++.brendan/array1.C index d6957cd95ae..08e68f68a13 100644 --- a/gcc/testsuite/g++.old-deja/g++.brendan/array1.C +++ b/gcc/testsuite/g++.old-deja/g++.brendan/array1.C @@ -2,5 +2,5 @@ // GROUPS passed array-bindings extern "C" int printf (const char *, ...); -char array[~(~((__SIZE_TYPE__)0ul)>>1)|~(((__SIZE_TYPE__)0ul)>>3)]; // { dg-error "39:size of array .array. is negative" } overflow in array dimension.* +char array[~(~((__SIZE_TYPE__)0ul)>>1)|~(((__SIZE_TYPE__)0ul)>>3)]; // { dg-error "39:exceeds maximum object size" } overflow in array dimension.* int main () { printf ("PASS\n"); return 0; } diff --git a/gcc/testsuite/g++.old-deja/g++.mike/p6149.C b/gcc/testsuite/g++.old-deja/g++.mike/p6149.C index 4cb18948d88..7009f547b44 100644 --- a/gcc/testsuite/g++.old-deja/g++.mike/p6149.C +++ b/gcc/testsuite/g++.old-deja/g++.mike/p6149.C @@ -1,4 +1,4 @@ // { dg-do assemble } // prms-id: 6149 -int a[3 - sizeof(double)]; // { dg-error "9:size of array .a. is negative" } +int a[3 - sizeof(double)]; // { dg-error "9:size .\[0-9\]+. of array .a. exceeds maximum object size" } diff --git a/gcc/testsuite/gcc.dg/large-size-array-3.c b/gcc/testsuite/gcc.dg/large-size-array-3.c index ea13b933ae5..0a83b9c4176 100644 --- a/gcc/testsuite/gcc.dg/large-size-array-3.c +++ b/gcc/testsuite/gcc.dg/large-size-array-3.c @@ -16,6 +16,6 @@ sub (int *a) int main (void) { - int a[DIM][DIM]; /* { dg-error "size of array 'a' is too large" } */ + int a[DIM][DIM]; /* { dg-error "exceeds maximum object size|size of array 'a' is too large" } */ return sub (&a[0][0]); } diff --git a/gcc/testsuite/gcc.dg/large-size-array-5.c b/gcc/testsuite/gcc.dg/large-size-array-5.c index 71ac47374f4..f9acdf4528b 100644 --- a/gcc/testsuite/gcc.dg/large-size-array-5.c +++ b/gcc/testsuite/gcc.dg/large-size-array-5.c @@ -3,7 +3,7 @@ typedef __SIZE_TYPE__ size_t; -extern char a[((size_t)-1 >> 1) + 1]; /* { dg-error "too large" } */ +extern char a[((size_t)-1 >> 1) + 1]; /* { dg-error "is too large" } */ extern char b[((size_t)-1 >> 1)]; -extern int c[(((size_t)-1 >> 1) + 1) / sizeof(int)]; /* { dg-error "too large" } */ +extern int c[(((size_t)-1 >> 1) + 1) / sizeof(int)]; /* { dg-error "exceeds maximum object size" } */ extern int d[((size_t)-1 >> 1) / sizeof(int)]; diff --git a/gcc/testsuite/gcc.dg/large-size-array.c b/gcc/testsuite/gcc.dg/large-size-array.c index 6ea76066934..79e371f4a77 100644 --- a/gcc/testsuite/gcc.dg/large-size-array.c +++ b/gcc/testsuite/gcc.dg/large-size-array.c @@ -16,6 +16,6 @@ sub (int *a) int main (void) { - int a[DIM][DIM]; /* { dg-error "size of array 'a' is too large" } */ + int a[DIM][DIM]; /* { dg-error "exceeds maximum object size" } */ return sub (&a[0][0]); } diff --git a/gcc/tree.c b/gcc/tree.c index b8be295d145..af7abd87b7a 100644 --- a/gcc/tree.c +++ b/gcc/tree.c @@ -7500,10 +7500,12 @@ compare_tree_int (const_tree t, unsigned HOST_WIDE_INT u) /* Return true if SIZE represents a constant size that is in bounds of what the middle-end and the backend accepts (covering not more than - half of the address-space). */ + half of the address-space). + When PERR is non-null, set *PERR on failure to the description of + why SIZE is not valid. */ bool -valid_constant_size_p (const_tree size) +valid_constant_size_p (const_tree size, cst_size_error *perr /* = NULL */) { if (POLY_INT_CST_P (size)) { @@ -7514,10 +7516,33 @@ valid_constant_size_p (const_tree size) return false; return true; } - if (! tree_fits_uhwi_p (size) - || TREE_OVERFLOW (size) - || tree_int_cst_sign_bit (size) != 0) - return false; + + cst_size_error error; + if (!perr) + perr = &error; + + if (TREE_OVERFLOW (size)) + { + *perr = cst_size_overflow; + return false; + } + + tree type = TREE_TYPE (size); + if (TYPE_UNSIGNED (type)) + { + if (!tree_fits_uhwi_p (size) + || tree_int_cst_sign_bit (size)) + { + *perr = cst_size_too_big; + return false; + } + } + else if (tree_int_cst_sign_bit (size)) + { + *perr = cst_size_negative; + return false; + } + return true; } @@ -15003,6 +15028,15 @@ const builtin_structptr_type builtin_structptr_types[6] = { const_fexcept_t_ptr_type_node, const_ptr_type_node, "fexcept_t" } }; +/* Return the maximum object size. */ + +tree +max_object_size (void) +{ + /* To do: Make this a configurable parameter. */ + return TYPE_MAX_VALUE (ptrdiff_type_node); +} + #if CHECKING_P namespace selftest { diff --git a/gcc/tree.h b/gcc/tree.h index 39b2ca51f76..a1c30e42cce 100644 --- a/gcc/tree.h +++ b/gcc/tree.h @@ -4347,7 +4347,18 @@ extern int tree_int_cst_sign_bit (const_tree); extern unsigned int tree_int_cst_min_precision (tree, signop); extern tree strip_array_types (tree); extern tree excess_precision_type (tree); -extern bool valid_constant_size_p (const_tree); + +/* Desription of the reason why the argument of valid_constant_size_p + is not a valid size. */ +enum cst_size_error { + cst_size_ok, + cst_size_negative, + cst_size_too_big, + cst_size_overflow +}; + +extern bool valid_constant_size_p (const_tree, cst_size_error * = NULL); +extern tree max_object_size (); /* Return true if T holds a value that can be represented as a poly_int64 without loss of precision. Store the value in *VALUE if so. */ -- 2.30.2