From 4b606faf44b11ba1155388afca7abfd5e922b023 Mon Sep 17 00:00:00 2001 From: Will Cohen Date: Wed, 4 Oct 2000 18:03:33 +0000 Subject: [PATCH] Patched code to generate warning when trying to perform static initialization of zero-length arrays. From-SVN: r36714 --- gcc/ChangeLog | 19 ++++++++----------- gcc/c-typeck.c | 3 ++- gcc/extend.texi | 4 ++++ 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 405b6914af8..eede1ca8496 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2000-10-04 Will Cohen + + * c-typeck.c (process_init_element): Added warning for zero-length + array. + + * extend.texi (Zero Length): State that static initializers for + zero-length arrays are not allowed. + Mon Oct 2 14:50:14 MET DST 2000 Jan Hubicka * rtlanal.c (single_set_1): Do not require USE and CLOBBERs @@ -1139,17 +1147,6 @@ Mon 18-Sep-2000 19:21:35 BST Neil Booth * config/sh/sh.md (sym_label2reg, symPLT_label2reg): Protect LABEL_REFs with a PIC-safe unspec. -2000-09-18 Will Cohen - - * extend.texi (Zero Length): State that static initializers for - zero-length arrays are not allowed. - - * c-typeck.c (process_init_element): Flag initializers for zero - length arrays. - - * tree.c (integer_all_onesp): Ignore TREE_INT_CST_HIGH if prec is - exactly HOST_BITS_PERWIDE_INT. - 2000-09-18 Joseph S. Myers * c-common.c (check_format_info): Properly save the argument diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c index da8ced243b8..9f2ec8d1e78 100644 --- a/gcc/c-typeck.c +++ b/gcc/c-typeck.c @@ -6460,7 +6460,8 @@ process_init_element (value) } if (constructor_max_index != 0 - && tree_int_cst_lt (constructor_max_index, constructor_index)) + && (tree_int_cst_lt (constructor_max_index, constructor_index) + || integer_all_onesp (constructor_max_index))) { pedwarn_init ("excess elements in array initializer"); break; diff --git a/gcc/extend.texi b/gcc/extend.texi index 40e57b34465..2c6b4d1d670 100644 --- a/gcc/extend.texi +++ b/gcc/extend.texi @@ -889,6 +889,10 @@ struct line @{ In standard C, you would have to give @code{contents} a length of 1, which means either you waste space or complicate the argument to @code{malloc}. +Static initialization of the zero-length array is not allowed. A +warning will be generated for each initializer attempting to initialize +the zero-length array. + @node Variable Length @section Arrays of Variable Length @cindex variable-length arrays -- 2.30.2