additional GCC warnings
additional GCC warnings
От:
Neil Conway <neilc@samurai.com>
Дата:
Recent versions of GCC support some additional warning flags that I
think would be useful to enable for building PostgreSQL:
-Wmissing-declarations ("Warn if a global function is defined without a
previous declaration.")
-Wdeclaration-after-statement (Recent versions of GCC allow declarations
and statements to be intermixed in C; enabling this flag would enforce
the current convention of avoiding this style.)
-Wold-style-definition (Warn if K&R-style function definitions are used.)
For the most part it won't take a lot of work to enable these flags.
Some code we imported into the tree from elsewhere might need to be
updated for -Wold-style-definition, but that should be easy.
Since some of these flags were added to GCC relatively recently, we
would probably need to test if the local gcc supports the flags via
configure.
Comments?
-Neil
Re: additional GCC warnings
От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Neil Conway writes:
> Recent versions of GCC support some additional warning flags that I
> think would be useful to enable for building PostgreSQL:
> -Wmissing-declarations ("Warn if a global function is defined without a
> previous declaration.")
Hm? We have always used that one.
> -Wdeclaration-after-statement (Recent versions of GCC allow declarations
> and statements to be intermixed in C; enabling this flag would enforce
> the current convention of avoiding this style.)
Ick. If the default is to allow that, then yes we need a warning.
I'd be fairly annoyed if it's not an error, in fact.
> Since some of these flags were added to GCC relatively recently, we
> would probably need to test if the local gcc supports the flags via
> configure.
Yeah, you would: it looks like gcc treats an unrecognized -W option
as an error:
$ gcc -Wabc z.c
cc1: Invalid option `-Wabc'
$ echo $?
1
$
regards, tom lane
Re: additional GCC warnings
От:
Neil Conway <neilc@samurai.com>
Дата:
On Mon, 2004-10-18 at 03:50, Tom Lane wrote:
> > -Wmissing-declarations ("Warn if a global function is defined without a
> > previous declaration.")
>
> Hm? We have always used that one.
We've always used -Wmissing-prototypes. The documentation states that
-Wmissing-prototypes instructs GCC to:
Warn if a global function is defined without a previous prototype declaration. This warning is issued even if the definition itself provides a prototype. The aim is to detect global functions that fail to be declared in header files.
Whereas -Wmissing-declarations does:
Warn if a global function is defined without a previous declaration. Do so even if the definition itself provides a prototype. Use this option to detect global functions that are not declared in header files.
Which doesn't make the difference in behavior between the two options
clear to me. Can anyone clarify this?
BTW, are these changes appropriate for 8.0?
-Neil
Re: additional GCC warnings
От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Neil Conway writes:
>>> -Wmissing-declarations ("Warn if a global function is defined without a
>>> previous declaration.")
>>
>> Hm? We have always used that one.
> We've always used -Wmissing-prototypes.
We've always used both. See Makefile.global.in:
ifeq ($(GCC), yes) CFLAGS += -Wall -Wmissing-prototypes -Wmissing-declarations
endif
> ... Which doesn't make the difference in behavior between the two options
> clear to me. Can anyone clarify this?
Hmm, it looks like -Wmissing-prototypes may be a superset of
-Wmissing-declarations --- it seems to say that the latter will be
content with a K&R style declaration ("extern int foo();") but the
former will not. If that's a correct reading then we could drop
-Wmissing-declarations.
regards, tom lane
Re: additional GCC warnings
От:
Neil Conway <neilc@samurai.com>
Дата:
On Mon, 2004-10-18 at 12:03, Tom Lane wrote:
> > We've always used -Wmissing-prototypes.
>
> We've always used both.
My apologies -- I don't know where I got the opposite impression.
> Hmm, it looks like -Wmissing-prototypes may be a superset of
> -Wmissing-declarations --- it seems to say that the latter will be
> content with a K&R style declaration ("extern int foo();") but the
> former will not. If that's a correct reading then we could drop
> -Wmissing-declarations.
Ok, that makes sense.
-Neil
Re: additional GCC warnings
От:
"Jeroen T. Vermeulen" <jtv@xs4all.nl>
Дата:
On Sun, Oct 17, 2004 at 01:50:46PM -0400, Tom Lane wrote: > > -Wdeclaration-after-statement (Recent versions of GCC allow declarations > > and statements to be intermixed in C; enabling this flag would enforce > > the current convention of avoiding this style.) > > Ick. If the default is to allow that, then yes we need a warning. > I'd be fairly annoyed if it's not an error, in fact. IIRC it's a new feature in C99. If that is the case, you may want to tell gcc simply to compile an older C dialect and get errors for all such newfangled code. Jeroen
Re: additional GCC warnings
От:
Peter Eisentraut <peter_e@gmx.net>
Дата:
Jeroen T. Vermeulen wrote: > IIRC it's a new feature in C99. If that is the case, you may want to > tell gcc simply to compile an older C dialect and get errors for all > such newfangled code. We make occasional, optional use of C99 features, so we don't want to turn it off completely. -- Peter Eisentraut http://developer.postgresql.org/~petere/