Why -Wredundant-decls in sys/conf/kern.mk?

Craig Rodrigues rodrigc at crodrigues.org
Tue Aug 2 05:42:01 GMT 2005


I am looking into getting the kernel to compile with gcc 4.0,
and encountered something which I am not sure about.

In sys/conf/kern.mk, why do we have -Wredundant-decls in the

CWARNFLAGS?=    -Wall -Wredundant-decls -Wnested-externs -Wstrict-prototypes \

I have no problems with the other warning flags.
However -Wredundant-decls warns for:

     Warn if anything is declared more than once in the same scope,
     even in cases where multiple declaration is valid and changes

This warning causes gcc to emit a warning for legal C code,
that normally not even -Wall would complain about.

For example, gcc compiles this code compiles fine, even with -Wall:

struct a { }; static struct a b;  static struct a b = { };

but emits a warning with -Wredundant-decls:
r.c:1: warning: redundant redeclaration of 'b'
r.c:1: warning: previous declaration of 'b' was here

There are places in the kernel that want to forward declare
a struct as static, and then implement it later on.
Since it is legal in C to do this, are we gaining anything
by having this flag in the kernel's CWARNFLAGS?
Does -Wredundant-decls warn against other things that are useful
to warn against?

Sorry if this is a silly question....I'm not a C expert.


Craig Rodrigues        
rodrigc at crodrigues.org

More information about the freebsd-current mailing list