https://bugs.llvm.org/show_bug.cgi?id=40350

            Bug ID: 40350
           Summary: Logic error that should not be reported (Converting a
                    pointer value of type 'NSNumber *' to a primitive
                    boolean value)
           Product: clang
           Version: unspecified
          Hardware: Macintosh
                OS: MacOS X
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Static Analyzer
          Assignee: dcough...@apple.com
          Reporter: o...@aggressive.se
                CC: dcough...@apple.com, llvm-bugs@lists.llvm.org

Common code like this:

NSNumber *num = [attributes objectForKey:key];
if (num)
{
    num.intValue ... etc. 
}

Generates this warning/error:

"Converting a pointer value of type 'NSNumber *' to a primitive boolean value;
instead, either compare the pointer to nil or call -boolValue"

Should not be reported, or be smarter - like if the number is actually being
used as a boolean and not as any other number. Like this:

//this should be ok, here it's clear how the variable is being used:
NSNumber *num = [attributes objectForKey:key];
if (num)
{
    _someValue = num.intValue;
}

//this is not ok:
NSNumber *num = [attributes objectForKey:key];
if (num)
{
    int somNumber = 5;
    attributes[key] = @(someNumber);  //num is only used as a bool.
}

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to