[LLVMbugs] [Bug 9194] New: clang should warn upon '== YES' with Obj-C BOOL

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Thu Feb 10 13:01:16 PST 2011


           Summary: clang should warn upon '== YES' with Obj-C BOOL
           Product: new-bugs
           Version: trunk
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: new bugs
        AssignedTo: unassignedbugs at nondot.org
        ReportedBy: sean at rogue-research.com
                CC: llvmbugs at cs.uiuc.edu

Since Objective-C predates C99, it defines it's own BOOL type instead of using
the standard bool. Unfortunately, Obj-C BOOL is in fact a 'signed char' and so
has 256 possible values instead of just 2.

It also defines NO=0 and YES=1. But what about the other 254 values? As per C
rules, they are all treated as true.  As such, testing == NO is safe, but
testing == YES is not (since YES is not the only true value).

rdar://problem/6510042 suggests that Obj-C adopt the C99 bool, but until

it would be nice if clang warned for any test of a BOOL variable with == YES


BOOL isOK = someBitField & someFlag; // isOK becomes, let's say, 66.
if (isOK == YES)


bool isOK = someBitField & someFlag; // isOK becomes either 0 or 1
if (isOK == true)

I would be happy with either the compiler or static analzyer warning about

Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.

More information about the llvm-bugs mailing list