Proposal: fine-grained control over -Werror

Omer Shenker mail@omershenker.net
Mon Mar 8 14:34:00 GMT 2004


Hello,

I would like to propose a new system for fine-grained control over which 
warnings to treat as errors. I believe my proposal would be easy to 
implement (as in, even I could write the patch) and backwards-compatible.

I propose that for each warning -Wfoo, GCC should also accept 
-Wfoo=error and -Wfoo=warn. As you might have guessed, -Wfoo=error means 
that warnings generated by -Wfoo are treated as errors while -Wfoo=warn 
gives the usual non-fatal warnings. Normally =warn is the default, and 
only =error is useful to specify. When -Werror is in use, =error is the 
default and =warn is available to turn it off.

For flags that turn on multiple classes of warnings, like -Wall, their 
arguments would apply to each member of the class. For example if -Wfoo 
turns on -Wbar and -Wbaz, then -Wfoo=error would imply -Wbar=error and 
-Wbaz=error.

This new system would not apply to -W, because there might be confusion 
between -Werror and -W=error and -W is deprecated for -Wextra anyway.

There would naturally be no point in accepting -Wno-foo=error, since 
it's hard to turn a disabled warning into an error. :)

I am throwing this out as a suggestion because I have often wished for 
it. For example, I almost always want what -Wformat-security=error and 
-Wsign-compare=warn would do. I am willing to try implementing it myself 
if the powers that be would be receptive to a patch, although I'm sure 
someone familiar with GCC internals could do it much faster.

(I should clarify what I mean by backwards-compatible. A quick test 
shows that -Wfoo=extra is an error in 3.3. So the new flags would not 
work on old compilers, but that is no surprise. Rather, the old flags 
will work on new compilers, because -Werror will still have the expected 
semantics.)

-- 
Omer Shenker



More information about the Gcc mailing list