This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: RFC: Named warnings


Zack Weinberg wrote:

Stan Shebs <shebs@apple.com> writes:

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"...

Whoops, you're right!  So much for proofreading... :-)

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 thought about adding on/off, but it wasn't clear who it was supposed
to benefit.  I suppose a total IDE user might come in using checkboxes
for warnings, and never see the -Wfoo/-Wno-foo convention, so sure.

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"...

That's a good idea!

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.


That makes sense too.  You could end up with funny-looking repetition
though:

fn() {
#pragma GCC warning "no-missing-prototypes"
 ugly_system_code;
#pragma GCC warning "missing-prototypes"
 my_good_code;
}
#pragma GCC warning "missing-prototypes"

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.

Yup, just wanted to get all the chest-clutching out of the way
(hundreds of new options all at once!  Omigod, everything is spinning
and growing dark :-) )

Stan




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]