[PATCH] RFC: Enabling -W[no-]error=... for cpplib warnings

Simon Baldwin simonb@google.com
Mon Oct 26 22:04:00 GMT 2009


At present in gcc, warnings emitted by cpplib can't be controlled in
the same way as those emitted by the C/C++ compiler proper.  For
example, -Werror=attributes will work, because attributes warnings are
issued by the main compiler, but -Werror=multichar won't because it's
handled in cpplib:

  $ cat /tmp/x.c
  int foo __attribute__((invalid));
  const char bar = 'bar';
  $ gcc -fdiagnostics-show-option -Werror=attributes -Werror=multichar
-Wno-overflow -o /dev/null -c /tmp/x.c
  /tmp/x.c:1: error: ‘invalid’ attribute directive ignored [-Wattributes]
  /tmp/x.c:2:18: warning: multi-character character constant

I'm working on a patch to address this for cpplib warnings that can be
attributed directly to gcc command line -W options, so that now:

  $ gcc/xgcc -Bgcc -fdiagnostics-show-option -Werror=attributes
-Werror=multichar -Wno-overflow -o /dev/null -c /tmp/x.c
  /tmp/x.c:1:1: error: ‘invalid’ attribute directive ignored [-Wattributes]
  /tmp/x.c:2:18: error: multi-character character constant [-Wmultichar]

The patch also adds a -Wno-warning-directive to control #warning, so
that warning directives can participate in -Werror= (so that
combinations like "-Werror -Wno-error=warning-directive" will work as
expected).

Before going through creating test cases for it, I'd appreciate any
comments or feedback on usefulness and approach.  Violent objections?
Overlap with something already in the pipeline?  The patch is a bit
invasive, but most of it is little more than separating out error and
warning cases in cpplib code.  Current working version attached below.

Thanks for any feedback.

--
Google UK Limited | Registered Office: Belgrave House, 76 Buckingham
Palace Road, London SW1W 9TQ | Registered in England Number: 3977902
-------------- next part --------------
A non-text attachment was scrubbed...
Name: cpp_warnings.patch
Type: text/x-diff
Size: 28632 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20091026/f9e3dc2b/attachment.bin>


More information about the Gcc-patches mailing list