[cfe-commits] [Patch] Checker for assignment of non-Boolean value to Boolean variable

Ryan Govostes rzg at apple.com
Thu Dec 8 17:49:29 PST 2011


On Dec 8, 2011, at 3:47 PM, David Blaikie wrote:

> Yeah, in that case it makes sense to have a check that ensures that
> pseudo-bool only ever contains the two well defined states. This
> totally makes sense as an SA diagnostic, etc.

This is what it does.

> If, on the other hand, 'x' is an int and someone's comparing it to
> true or false - I'd say that's probably a reasonable compiler warning.

Yes, there are a few compiler warning related to Booleans that would be useful:

- Comparison of Boolean to value other than 0 or 1.
- Comparison of non-Boolean to (named) Boolean constant.
- Mathematical or bitwise operation with Boolean operands.

> Or if we're complaining about int assigned to C++ 'bool' just because
> it collapses all non-zero values to 'true', then I don't really get
> it.

I did not know this about the C++ bool data type, but you are right. This is interesting for the checker: It should probably not warn on assignment of non-0/1 value to a C++ bool.

Ryan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20111208/cf1f1c69/attachment.html>


More information about the cfe-commits mailing list