c/4784: Anonymous structs issues

Joseph S. Myers jsm28@cam.ac.uk
Fri Mar 7 10:50:00 GMT 2003


On 7 Mar 2003 bangerth@dealii.org wrote:

>     Hm, with 3.3 and present mainline, we get on this code
>     -----------------------
>     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).  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)?

>     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 (C++ has its own rules;  
this is a C extension), but those error messages are the sort of error I
think the C front end ought to be giving: they accurately diagnose what
the problem in the example code is.

-- 
Joseph S. Myers
jsm28@cam.ac.uk



More information about the Gcc-bugs mailing list