From ee54eda045a47253f458e73702bf775eb4a21d4c Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Wed, 5 Oct 2016 09:13:55 -0700 Subject: [PATCH] utimecmp: avoid new GCC 7 warning from -Wbool-operation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Testing this module would fail when using GCC 7 like this: $ CFLAGS='-O -Werror=bool-operation' ./gnulib-tool --create-testdir \ --dir=/tmp/x --with-tests --test utimecmp ../../gllib/utimecmp.c: In function ‘utimecmp’: ../../gllib/utimecmp.c:291:36: error: ‘~’ on a boolean expression \ [-Werror=bool-operation] time_t s = src_s & ~ (res == 2 * BILLION); ^ ../../gllib/utimecmp.c:370:16: error: ‘~’ on a boolean expression \ [-Werror=bool-operation] src_s &= ~ (res == 2 * BILLION); ^ * lib/utimecmp.c (utimecmp): Do not apply "~" to a boolean. Instead, make it explicit that we intend to apply it to 0 or 1. --- ChangeLog | 18 ++++++++++++++++++ lib/utimecmp.c | 4 ++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7a3171c..71de7fa 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,21 @@ +2016-10-05 Jim Meyering + + utimecmp: avoid new GCC 7 warning from -Wbool-operation + Testing this module would fail when using GCC 7 like this: + $ CFLAGS='-O -Werror=bool-operation' ./gnulib-tool --create-testdir \ + --dir=/tmp/x --with-tests --test utimecmp + ../../gllib/utimecmp.c: In function ‘utimecmp’: + ../../gllib/utimecmp.c:291:36: error: ‘~’ on a boolean expression \ + [-Werror=bool-operation] + time_t s = src_s & ~ (res == 2 * BILLION); + ^ + ../../gllib/utimecmp.c:370:16: error: ‘~’ on a boolean expression \ + [-Werror=bool-operation] + src_s &= ~ (res == 2 * BILLION); + ^ + * lib/utimecmp.c (utimecmp): Do not apply "~" to a boolean. + Instead, make it explicit that we intend to apply it to 0 or 1. + 2016-10-02 Jim Meyering vasnprintf.c: avoid spurious warning from GCC 7 diff --git a/lib/utimecmp.c b/lib/utimecmp.c index ac3d626..c2e3057 100644 --- a/lib/utimecmp.c +++ b/lib/utimecmp.c @@ -288,7 +288,7 @@ utimecmp (char const *dst_name, to interrogate the file system to deduce the exact time stamp resolution; return the answer directly. */ { - time_t s = src_s & ~ (res == 2 * BILLION); + time_t s = src_s & ~ (res == 2 * BILLION ? 1 : 0); if (src_s < dst_s || (src_s == dst_s && src_ns <= dst_ns)) return 1; if (dst_s < s @@ -367,7 +367,7 @@ utimecmp (char const *dst_name, } /* Truncate the source's time stamp according to the resolution. */ - src_s &= ~ (res == 2 * BILLION); + src_s &= ~ (res == 2 * BILLION ? 1 : 0); src_ns -= src_ns % res; } -- 2.7.4