RFC: Named warnings

Zack Weinberg zack@codesourcery.com
Fri Jan 24 02:26:00 GMT 2003


Stan Shebs <shebs@apple.com> writes:

> This RFC proposes a uniform system for handling GCC's warnings, based
> on the use of names to distinguish every type of warning.  A uniform
> system would make every one of GCC's warnings individually
> controllable, and enable the use of pragmas and/or attributes to
> control warnings within a translation unit.  

I support this initiative.  A couple of specific comments:

> Attributes are useful for limiting effect to single functions or
> variables, but are unduly repetitive for long files with many
> functions and variables.  Pragmas would work better then, as in
>
> #pragma GCC "no-sign-compare" "switch"
> ...
> #pragma GCC "sign-compare" "switch" "missing-prototypes"
...
> The effect of each pragma is a one-way change to the warnings listed.
> (It would be possible to have warning control pragmas with a push/pop
> behavior, but this seems excessive complicated, both to implement and
> to use correctly.)

First: that should be

#pragma GCC warning "name"...

as the convention is that pragmas are named.  Second, I think a spot
of syntactic sugar would be nice:

#pragma GCC warning [on|off] "name"...

This notation is compatible with the C99 standard pragmas, all of
which are of the form #pragma STDC foo (ON|OFF).  Your "no-foo"
convention can work too.

I agree we don't need a complete stack, but I think there should be a
way of saying 'go back to whatever was set by command line switches':
perhaps

#pragma GCC warning revert "name"...

Also to consider: if this pragma is used at block scope its effects
are reverted at the end of the block, just like the C99 standard
pragmas.

> Finally, while -Werror is a useful option, it's difficult to use
> reliably in portable software (as witness GCC's own recent travails)
> because it affects all enabled warnings.  It just so happens that
> -Efoo is not used for anything now, so I propose that -Efoo be defined
> to work equivalently to -Wfoo -Werror for warning "foo" only.  There
> are complexities with random combos like -Wfoo -Eno-foo -Wno-foo
> -Efoo, and these need more thought before implementing.

No objection in principle, but we do need to thrash out all the
complexities first.

Oh, we should get Phil's -Wextra patch in first (or did it finally get
approved?)

zw



More information about the Gcc mailing list