[PATCH 3.4] Warn for always-false bitwise ands

John Levon levon@movementarian.org
Sat Mar 22 01:03:00 GMT 2003


On Fri, Mar 21, 2003 at 01:03:54PM -0800, Richard Henderson wrote:

> I should have gotten back to you earlier.

No problem ..

> First of all, a warning like "bitwise and expression is always false"
> should be on always, much like we do with "comparison is always false
> due to limited range of data type".

The latter is much much more likely to be an error than the former,
IMHO. I can conceive of someone using defines and invoking the former
warning, but not the latter - it's like if (0) ...

> Second, the warning is incorrect for any constant with low bit set,
> not just 1.  However, I'm willing to allow that this is likely to
> be a mistake -- even with 1.  About this I'm not sure what to do.

I guess I don't understand this. What source code changes do you want me
to make ?

> I'm thinking an unconditional warning "suggest && instead of &
> with booleans".

This is obviously wrong: 90% of the problems are parentheses issues,
i.e. if (!a & 0x4) vs. if (!(a & 0x4))

> Also, your C and C++ tests should be nearly identical.  There is
> a boolean type in C99: _Bool (available as bool if you include
> <stdbool.h>).

Sure, but does this really matter ?

regards,
john



More information about the Gcc-patches mailing list