This is the mail archive of the
mailing list for the glibc project.
Re: Add macros for diagnostic control, use them in locale/weightwc.h
- From: Paul Eggert <eggert at cs dot ucla dot edu>
- To: Joseph Myers <joseph at codesourcery dot com>, libc-alpha at sourceware dot org
- Date: Fri, 21 Nov 2014 09:43:23 -0800
- Subject: Re: Add macros for diagnostic control, use them in locale/weightwc.h
- Authentication-results: sourceware.org; auth=none
- References: <alpine dot DEB dot 2 dot 10 dot 1411181803130 dot 11642 at digraph dot polyomino dot org dot uk> <alpine dot DEB dot 2 dot 10 dot 1411211705270 dot 2475 at digraph dot polyomino dot org dot uk>
A couple of other thoughts.
First, the syntax DIAG_IGNORE (-Wmaybe-uninitialized, ...) is too clever and
brittle. Too clever, because in C code it looks like it's subtracting
'uninitialized' from the negative of 'Wmaybe'. Too brittle, because suppose GCC
adds a warning option syntax with commas in it?
"-Wsuggest-attribute=format,noreturn", say? Then DIAG_IGNORE
(-Wsuggest-attribute=format,noreturn, ...) won't work because of C's
tokenization rules. For both of these reasions it would be better to use a
string, e.g., DIAG_IGNORE ("-Wmaybe-uninitialized", ...).
More important, I looked through some of the Gnulib and GNU utilities code that
deals with working around bugs in GCC's diagnostics generation, and
-Wmaybe-uninitialized in particular has caused us so much grief that we
typically silence it in a different way, which I should mention. We use a macro
definition like this:
# define IF_LINT(Code) Code
# define IF_LINT(Code) /* empty */
and then write declarations like this:
off_t size IF_LINT ( = 0);
when GCC wrongly complains that 'size' may be used unininitialized. That way,
people who want to use -Wmaybe-uninitialized can get clean compiles by compiling
with '-Wmaybe-uninitialized -Dlint', and people who don't care about this stuff
can omit the options and get slightly more-efficient code. Obviously there are
some pitfalls in this approach but overall its benefits outweigh its cost for
us. In particular, it lets us carefully isolate the uninitialized-warning bug,
whereas the DIAG_IGNORE approach is more of a blunderbuss that disables the
warning in a too-large region because of GCC's bugs.