This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: Patch to warn about static initializers for zero length arrays
- To: gcc-patches at gcc dot gnu dot org
- Subject: Re: Patch to warn about static initializers for zero length arrays
- From: Will Cohen <wcohen at redhat dot com>
- Date: Wed, 04 Oct 2000 12:17:36 -0400
- Organization: Red Hat, Inc.
- References: <39C633EC.81E9FDD5@redhat.com>
I have a short C program that verifies that the patch to warn about
zero length arrays work. Should I install this file in
gcc/gcc/testsuite/gcc.dg?
I noticed that gcc/gcc/ChangeLog lists the changes I made, but the files
that
are suppose to have those changes, e.g. c-typeck.c and extend.texi, do
not
have the listed changes. Should I check in those changes and correct
the
ChangeLog to reflect the date the changes made?
-Will
Will Cohen wrote:
>
> The following patch makes gcc print warnings for initializers of
> zero length arrays as excess initializers. This moves gcc toward
> conforming with the C99 standard on flexible arrays (6.7.2.1).
>
> * 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.
>
> I have also attached a file, zerolength.c, which demonstrates gcc
> warning about the initializer. Assuming that the patch is installed
> the following messages should be generated:
>
> bash$ native/gcc/xgcc -Bnative/gcc/ -c zerolength.c
> zerolength.c:20: warning: excess elements in array initializer
> zerolength.c:20: warning: (near initialization for `playbook.Play')
>
> -Will Cohen
>
> ------------------------------------------------------------------------
> Name: 104153b.patch
> 104153b.patch Type: Plain Text (text/plain)
> Encoding: 7bit
>
> Name: zerolength.c
> zerolength.c Type: Plain Text (text/plain)
> Encoding: 7bit
/* Copyright (C) 2000 Free Software Foundation.
by William Cohen <wcohen@redhat.com> */
/* { dg-do compile } */
/* { dg-options "" } */
struct PDATA
{
unsigned int Dummy:32;
const char* PName;
};
typedef struct PDATA P_DATA;
struct PLAYBOOK {
const char * BookName;
P_DATA Play[0];
};
struct PLAYBOOK playbook =
{
"BookName",
{
{ 1, "PName0" }, /* { dg-warning "excess elements in array initializer|(near initialization for `playbook.Play')" } */
}
};