Skip to content

Generated methods that return BOOL should return NO instead of 0. #8

@seanm

Description

@seanm

AnalysisTool (http://www.karppinen.fi/analysistool/) which in turn uses the llvm static analyzer generates warnings for mogenerated code. ex:

  • (BOOL)primitiveIsLeafValue {
    NSNumber *result = [self primitiveIsLeaf];
    return result ? [result boolValue] : 0;
    }

It warns "coercion from 'int' to 'BOOL' may alter its value". Of course, there isn't really anything wrong with the code above, but the warning could be easily silenced by changing that 0 to a NO. That would fix it because the definition of NO includes a cast to BOOL.

This warning is useful in other situations but all these false positives are generating a lot of noise.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions