[Spice-devel] [PATCH spice-gtk 00/15] Expand usage of compiler warnings

Daniel P. Berrange berrange at redhat.com
Tue Mar 13 06:39:58 PDT 2012


The current spice-gtk configure.ac script only enables

 -Wall -Wno-sign-compare -Werror -Wno-deprecated-declarations

IMHO, this is not enough, and applications should strive to enable
as many GCC warning options as is practical for their codebase.
Rather than taking a whitelist approach to compiler warnings, take
a blacklist approach - enable every GCC warning except those you
don't want.

GNULIB makes this very easy, since it has a record of all known
GCC warnings, and some m4 macros to facilitate calculating the
desired set. spice-gtk doesn't use GNULIB, but this particular
m4 file is essentially standalone, so trivially copyable into
the spice-gtk source without having to fully integrate with
GNULIB.

The first 14 patches in this series fix misc issues in the code
which would otherwise trigger warnings. The last patch actually
enables the warnings. It also enables some GCC runtime protection
features, commonly used by distros in their packages

On my Fedora 16 host, this results in the following compiler flags
being used

  -Wall -W -Wformat-y2k -Wformat-security -Winit-self
  -Wmissing-include-dirs -Wunused -Wunknown-pragmas
  -Wstrict-aliasing -Wpointer-arith -Wcast-align -Wwrite-strings
  -Wlogical-op -Waggregate-return -Wstrict-prototypes
  -Wold-style-definition -Wmissing-noreturn
  -Wmissing-format-attribute -Wredundant-decls -Wnested-externs
  -Winvalid-pch -Wvolatile-register-var -Wdisabled-optimization
  -Wbuiltin-macro-redefined -Wmudflap -Wpacked-bitfield-compat
  -Wsync-nand -Wattributes -Wcoverage-mismatch -Wmultichar
  -Wcpp -Wdeprecated-declarations -Wdiv-by-zero
  -Wdouble-promotion -Wendif-labels -Wextra
  -Wformat-contains-nul -Wformat-extra-args
  -Wformat-zero-length -Wformat=2 -Wmultichar -Wnormalized=nfc
  -Woverflow -Wpointer-to-int-cast -Wpragmas
  -Wsuggest-attribute=const -Wsuggest-attribute=noreturn 
  -Wsuggest-attribute=pure -Wtrampolines
  -Wno-missing-field-initializers -Wno-sign-compare
  -Wno-unused-parameter -Wno-format-nonliteral
  -Wjump-misses-init -Wno-format-nonliteral
  -Wframe-larger-than=1152 -fstack-protector-all
  --param=ssp-buffer-size=4 -fexceptions
  -fasynchronous-unwind-tables -fdiagnostics-show-option
  -funit-at-a-time -fipa-pure-const
  -Wno-suggest-attribute=pure -Wno-suggest-attribute=const

It will automagically turn on -Werror if it sees $srcdir/.git
so developers get hit with a hard stick, while end users
building from tar.gz avoid it.

For future usage the m4/spice-compile-warnings.m4 file is
where the set of flags can be tuned.

As new GCC releases come out, the m4/many-warnings.m4 file
can be periodically refreshed from GNULIB GIT, to pick up
any new warning flags.




More information about the Spice-devel mailing list