On 2012-04-05 10:48:29 +0100, Pedro Alves wrote: > On 04/05/2012 10:39 AM, Richard Guenther wrote: > > ... [-Wall + -Werror] ... > > > Btw, it would be more reasonable to enable a subset of warnings that > > we enable at -Wall by default. Notably those that if they were not > > false positives, would lead to undefined behavior at runtime. Specifically > > I don't think we should warn about unused static functions or variables > > by default. > > Yes, I would agree more with something like that.
Ditto. I sometimes get such warnings just because of the use of the preprocessor. However taking the preprocessor into account would mean that some useful warnings (perhaps even with currently default ones, but I'm not sure because I always use -Wall) could not be included. The best solution is sometimes to modify the source. For instance, I had to do the following change (not sure whether this is the best way) in MPFR a few days ago: Index: src/const_euler.c =================================================================== --- src/const_euler.c (revision 8123) +++ src/const_euler.c (revision 8124) @@ -118,7 +118,7 @@ int inex; MPFR_BLOCK_DECL (flags); - MPFR_BLOCK (flags, inex = mpfr_get_z (P, n, MPFR_RNDN)); + MPFR_BLOCK (flags, MPFR_DBGRES (inex = mpfr_get_z (P, n, MPFR_RNDN))); MPFR_ASSERTD (inex == 0 && ! MPFR_ERANGEFLAG (flags)); if (a > 1) mpz_mul_si (P, P, 1 - (long) a); Index: src/mpfr-impl.h =================================================================== --- src/mpfr-impl.h (revision 8123) +++ src/mpfr-impl.h (revision 8124) @@ -388,12 +388,18 @@ #define MPFR_ASSERTN(expr) \ ((void) ((MPFR_UNLIKELY(expr)) || MPFR_UNLIKELY( (ASSERT_FAIL(expr),0) ))) -/* MPFR_ASSERTD(expr): assertions that should be checked when testing */ +/* MPFR_ASSERTD(expr): assertions that should be checked when testing. + MPFR_DBGRES(assignment): to be used when the result is tested only + in an MPFR_ASSERTD expression (in order to avoid a warning, e.g. + with GCC's -Wunused-but-set-variable, in non-debug mode). + */ #ifdef WANT_ASSERT # define MPFR_EXP_CHECK 1 # define MPFR_ASSERTD(expr) MPFR_ASSERTN (expr) +# define MPFR_DBGRES(A) (A) #else # define MPFR_ASSERTD(expr) ((void) 0) +# define MPFR_DBGRES(A) ((void) (A)) #endif /* Code to deal with impossible -- Vincent Lefèvre <vinc...@vinc17.net> - Web: <http://www.vinc17.net/> 100% accessible validated (X)HTML - Blog: <http://www.vinc17.net/blog/> Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)