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

--- Comment #13 from dagelf <coenraad at wish dot org.za> ---
Yes, I seem to have had a hole in my head. Sorry. For reference, to summarise
then:

& returns only the bits that are the same (bitwise AND) (or the bits that are
left after AND) (which will evaluate to true unless its 0 eg. (2 & 1) is false
but (3 & 1) is true. 

&& casts operands to bool, so anything nonzero becomes 1. (eg. (2 && 1) is
true)

&& and & nonequivalence: https://godbolt.org/z/Yf5cxcKch

So & and && are only interchangeable when operating on bool parameters, on
anything else they each do something completely different. 

The fact that there's a warning is great. Perhaps its fine. But this is
something so fundamental, it feels like no room for confusion should be left.
In fact, the more I think about it, the more I am convinced that it should not
be a warning, but an error, so -Werror is my new default. 

Although I would love to find counter examples, I would be willing to wager
that && mixed with non bools, will almost always be done in error.

Reply via email to