On Tue, May 2, 2023 at 2:56 PM Bruno Haible <br...@clisp.org> wrote:
>
> The continuous integration of 'gzip' failed today:
>
>   CC       fopen.o
> fopen.c: In function 'rpl_fopen':
> fopen.c:50:7: error: variable 'open_direction' set but not used 
> [-Werror=unused-but-set-variable]
>    50 |   int open_direction;
>       |       ^~~~~~~~~~~~~~
> cc1: all warnings being treated as errors
> make[6]: *** [Makefile:2311: fopen.o] Error 1
>
> Contributing factors are:
>   - There is a depencency from module 'fclose' to module 'fopen' since last
>     week.
>   - The variable 'open_direction' is set but possibly not used (depending
>     on #if conditions).
>   - gzip's configuration apparently enables many warnings and -Werror.
>   - The fopen module uses AC_LIBOBJ, in order to avoid link error w.r.t.
>     to modules fopen vs. fopen-gnu.
>   - In AC_LIBOBJ compilation units, Gnulib's override of the CFLAGS with
>     -Wno-error has no effect.
>
> The easiest fix is the following:
>
>
> 2023-05-02  Bruno Haible  <br...@clisp.org>
>
>         fopen: Silence a gcc warning.
>         * lib/fopen.c (rpl_fopen): Mark open_direction as used.
>
> diff --git a/lib/fopen.c b/lib/fopen.c
> index f8469a0bbc..e1e4cdbd23 100644
> --- a/lib/fopen.c
> +++ b/lib/fopen.c
> @@ -225,5 +225,9 @@ rpl_fopen (const char *filename, const char *mode)
>      }
>  #endif
>
> +  /* open_direction is sometimes used, sometimes unused.
> +     Silence gcc's warning about this situation.  */
> +  (void) open_direction;
> +
>    return orig_fopen (filename, mode);
>  }

It may be a good idea to hide it behind a self-documenting macro:

    #define GNULIB_MAYBE_UNUSED(x) ((void)(x))
    ...

    GNULIB_MAYBE_UNUSED(open_direction);

Jeff

Reply via email to