[LLVMbugs] [Bug 15774] BoolAssignmentChecker not catching literals

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Fri Apr 19 17:42:03 PDT 2013


Jordan Rose <jordan_rose at apple.com> changed:

           What    |Removed                     |Added
             Status|NEW                         |RESOLVED
                 CC|                            |jordan_rose at apple.com
         Resolution|---                         |INVALID

--- Comment #1 from Jordan Rose <jordan_rose at apple.com> ---
BoolAssignmentChecker isn't actually for checking C++/C99 bool; it's for types
that are intended to be used as boolean variables but are actually typedefs of
small integers, like Objective-C's BOOL.

Why the distinction? For 'bool', coercion/casting always gives the same answer
as testing with an if, while, or ?:. But for 'BOOL', a cast results in
truncation, rather than truth-testing.

Similarly, you can safely compare a 'bool' variable against 'false' or 'true',
but a 'BOOL' variable may not always be 'NO' (0) or 'YES' (1), although it
probably ought to be.

So, yes, this is by design. You could argue that relying on an implicit
int-to-boolean conversion is bad style, but that would be a separate argument,
not a bug in the current checker. :-)

You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20130420/d43dca70/attachment.html>

More information about the llvm-bugs mailing list