c/4784: Anonymous structs issues

Wolfgang Bangerth bangerth@ticam.utexas.edu
Fri Mar 7 15:14:00 GMT 2003


> >     -----------------------
> >     struct s {
> >         int x;
> >         struct { int x; };
> >     };
> >     ------------------
> >     the following message:
> >     g/x> /home/bangerth/bin/gcc-3.4-pre/bin/gcc -W -Wall -std=c99 -c x.c
> >     x.c:3: warning: declaration does not declare anything
> 
> What's relevant is -std=gnu99 and -std=gnu89, as this is a GNU extension.
> That warning hardly diagnoses what the problem is; the point of the 
> extension is that certain declarations that don't declare anything do, in 
> fact, declare nested anonymous struct elements.  The PR asks for a hard 
> error (with a more sensible error message).

Ah, ok. Thanks for clarifying this (seems I am not familiar enough with 
the subtleties of gnu extensions). I just checked, and 3.4 with -std=gnu99 
accepts the code without any warnings, indeed.

> What about more complicated cases, such as:
> 
> struct s {
>   struct {
>     int a;
>     struct {
>       int b;
>     };
>   };
>   struct {
>     int b;
>     int c;
>   };
> };
> 
> (where the duplicate "b" elements should be diagnosed)?

The same, it isn't.

> >     gcc3.2 is quiet. If compiled in C++ mode, we get this:
> >     g/x> /home/bangerth/bin/gcc-3.4-pre/bin/gcc -W -Wall -c x.cc
> >     x.cc:3: error: declaration of `int s::<anonymous struct>::x'
> >     x.cc:2: error: conflicts with previous declaration `int s::x'
> >     x.cc:3: error: duplicate member `s::<anonymous struct>::x'
> >     
> >     Joseph, is this approximately what you wanted gcc to
> >     tell us?
> 
> What the C++ compiler does isn't part of the PR [...]

Sorry, I wasn't clear enough. I had wanted to know whether this is what 
you would also like the C frontend to issue. You answered this already.

Thanks for clarifying matters
  Wolfgang


PS: Joseph, I have an unrelated favor that I'd like to ask you for: you 
have a lot of reports where you point to some mail or a testcase. Figuring 
out what exactly is the claim of this report can sometimes be tedious, and 
leads to situations like the one above where I missed that this is 
actually a gnu extension. It would be much simpler if you could copy and 
paste a small example program from the cited sources into the PR (for the 
present one, there was a one-liner in the message you pointed to, but no 
command line or mention of gnu99), and a short description (3-5 lines) of 
what you expect with what command line. -- Thanks!

-------------------------------------------------------------------------
Wolfgang Bangerth             email:            bangerth@ticam.utexas.edu
                              www: http://www.ticam.utexas.edu/~bangerth/




More information about the Gcc-bugs mailing list