diff options
Diffstat (limited to 'gcc/cp/init.c')
-rw-r--r-- | gcc/cp/init.c | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/gcc/cp/init.c b/gcc/cp/init.c index efbda3a..606d246 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -3086,7 +3086,21 @@ build_new_1 (vec<tree, va_gc> **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<tree, va_gc> **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<tree, va_gc> **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)); |