From 1be51a3a9ac3409561223c8058d4943f9b574d15 Mon Sep 17 00:00:00 2001 From: Martin Sebor Date: Mon, 12 Oct 2020 09:35:02 -0600 Subject: PR c++/97201 - ICE in -Warray-bounds writing to result of operator new(0) gcc/cp/ChangeLog: PR c++/97201 * error.c (dump_type_suffix): Handle both the C and C++ forms of zero-length arrays. libstdc++-v3/ChangeLog: PR c++/97201 * libsupc++/new (operator new): Add attribute alloc_size and malloc. gcc/testsuite/ChangeLog: PR c++/97201 * g++.dg/warn/Wplacement-new-size-8.C: Adjust expected message. * g++.dg/warn/Warray-bounds-10.C: New test. * g++.dg/warn/Warray-bounds-11.C: New test. * g++.dg/warn/Warray-bounds-12.C: New test. * g++.dg/warn/Warray-bounds-13.C: New test. --- gcc/cp/error.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'gcc/cp') diff --git a/gcc/cp/error.c b/gcc/cp/error.c index ad22b00..396558b 100644 --- a/gcc/cp/error.c +++ b/gcc/cp/error.c @@ -951,8 +951,11 @@ dump_type_suffix (cxx_pretty_printer *pp, tree t, int flags) if (tree dtype = TYPE_DOMAIN (t)) { tree max = TYPE_MAX_VALUE (dtype); - /* Zero-length arrays have an upper bound of SIZE_MAX. */ - if (integer_all_onesp (max)) + /* Zero-length arrays have a null upper bound in C and SIZE_MAX + in C++. Handle both since the type might be constructed by + the middle end and end up here as a result of a warning (see + PR c++/97201). */ + if (!max || integer_all_onesp (max)) pp_character (pp, '0'); else if (tree_fits_shwi_p (max)) pp_wide_integer (pp, tree_to_shwi (max) + 1); -- cgit v1.1