Discussion:
FYI: [PATCH] utimecmp: avoid new GCC 7 warning from -Wbool-operation
(too old to reply)
Jim Meyering
2016-10-05 16:17:18 UTC
Permalink
Raw Message
Without this (just pushed) and some other changes, I could not build
coreutils using GCC 7:
Paul Eggert
2016-10-05 16:51:43 UTC
Permalink
Raw Message
* lib/utimecmp.c (utimecmp): Do not apply "~" to a boolean.
Hah! And just Monday I was telling students how C operations like binary
+, unary and binary -, and ~ can produce non-boolean outputs when given
boolean inputs. That's a feature, not a bug.

While I'm ranting, another thing that bothers me is that gcc -Wall
doesn't know that == is both commutative and associative on booleans: it
complains about "a==b==c" even when all arguments are boolean so that
inserting parentheses cannot reduce ambiguity. It's times like this that
I think GCC's '-Wall' option should really be called '-Wnanny'.
Jim Meyering
2016-10-05 17:47:19 UTC
Permalink
Raw Message
* lib/utimecmp.c (utimecmp): Do not apply "~" to a boolean.
Hah! And just Monday I was telling students how C operations like binary +,
unary and binary -, and ~ can produce non-boolean outputs when given boolean
inputs. That's a feature, not a bug.
While I'm ranting, another thing that bothers me is that gcc -Wall doesn't
know that == is both commutative and associative on booleans: it complains
about "a==b==c" even when all arguments are boolean so that inserting
parentheses cannot reduce ambiguity. It's times like this that I think GCC's
'-Wall' option should really be called '-Wnanny'.
I agree. I did not like to dirty utimecmp.c with that patch, but it seemed
better than disabling the warning altogether. If you'd prefer, we an do
the #pragma push/disable-warning/pop dance around that code, but
that seems like overkill.
Paul Eggert
2016-10-05 19:39:18 UTC
Permalink
Raw Message
we can do
the #pragma push/disable-warning/pop dance around that code, but
that seems like overkill.
Agreed, it's overkill. Also, I was tempted to suggest -1-x instead of
~(x?1:0) but that assumes two's complement. So let's just leave it
alone. At least GCC is smart enough to optimize it as if it were ~x.

I filed a GCC bug report here:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77876

I hope they fix it one way or another.

Jim Meyering
2016-10-05 17:49:14 UTC
Permalink
Raw Message
Post by Jim Meyering
Without this (just pushed) and some other changes, I could not build
Here's one more: with this, coreutils' subset of gnulib compiles
warning/error free.
Loading...