This is the mail archive of the
gdb@sources.redhat.com
mailing list for the GDB project.
Re: suggested compile warnings
- From: Andrew Cagney <ac131313 at redhat dot com>
- To: "Theodore A. Roth" <troth at openavr dot org>
- Cc: gdb at sources dot redhat dot com
- Date: Fri, 23 May 2003 16:15:56 -0400
- Subject: Re: suggested compile warnings
- References: <Pine.LNX.4.53.0305231130230.32235@knuth.amplepower.com>
Hi,
I've always been configuring gdb with --enable-gdb-build-warnings=-Werror
and thought that there where a bunch of gcc compile warnings issued.
Looking more closely at my builds, that doesn't seem to be true.
For my own apps, I like to use '-Wall -Werror' as it lets the compiler
catch a lot of my stupid mistakes. I tried '-Wall -Werror' for gdb,
but that seems to be too restrictive for gdb source.
Does anyone else compile gdb with any of the -W<foo> gcc options?
Is there a recommended list of these which should be used?
For example, adding -Wunused (without -Werror), turns up 149 wanrings.
Most are unused variables, some are static decl's for functions that
aren't defined. Most if not all of these should be trivial to fix.
See: 13.4.3 Compiler Warnings
http://sources.redhat.com/gdb/current/onlinedocs/gdbint_13.html#SEC118
Instead of -Wunused, look at the individual -Wunused-function,
-Wunused-variable, ...
Off hand, other intersting ones are:
-Wwrite-strings
It's just hard and really messy. People occasionally chip away at the
edges. Last time I tried, I came across what appeared to be an
effective xfree("string"), outch!
-W
More for the sign VS unsigned checks it throws up, but it throws up some
non problems :-(
-Wswitch-default
-Wswitch-enum
-Wswitch-fallthrough (doesn't actually exist)
But that could be religious :-)
-Wstrict-prototypes
-Wmissing-prototypes
-Wmissing-declarations
But tread carefully, it tends to run a foul of head files.
The trick is to first identify warnings that add real value (-Wformat
for instance is good++) and then ensure that the fix is not worse than
the problem being identified (using a cast to hide a problem, for
instance, isn't a good idea vis: xffree ((char *) "a string")).
I've appended an old list of the error counts for various flags that was
generated by compiling all the cross targets on a Red Hat GNU/Linux 7.2
system and then deleting duplicates (which GCC? I don't remember).
Have fun.
Andrew
590 W
217 Waggregate-return
335 Wall
8 Wbad-function-cast
4 Wcast-align
106 Wcast-qual
4 Wchar-subscripts
4 Wcomment
2913 Wconversion
4 Wdeprecated-declarations
4 Werror
11 Wfloat-equal
4 Wformat-extra-args
4 Wformat-nonliteral
4 Wformat-security
4 Wformat-y2k
4 Wformat
109 Wformat=2
7 Wimplicit-function-declaration
4 Wimplicit-int
7 Wimplicit
4 Wimport
4 Winline
4 Wlong-long
6 Wmain
20 Wmissing-braces
314 Wmissing-declarations
57 Wmissing-noreturn
341 Wmissing-prototypes
4 Wmultichar
51 Wnested-externs
5 Wpacked
101 Wpadded
4 Wparentheses
4 Wpointer-arith
356 Wredundant-decls
4 Wreturn-type
840 Wshadow
340 Wsign-compare
74 Wstrict-prototypes
44 Wswitch
488 Wtraditional
4 Wtrigraphs
26 Wundef
4 Wuninitialized
4 Wunknown-pragmas
213 Wunreachable-code
66 Wunused-function
8 Wunused-label
1420 Wunused-parameter
12 Wunused-value
200 Wunused-variable
274 Wunused
4421 Wwrite-strings