Warn when a Objective-C literal is converted to a boolean. This warns on NSNumber*, NSString*, NSArray* and NSDictionary* literals. Excludes objc_yes and objc_no.
I don't normally work with Objective-C so let me know if I am missing any test cases.
Differential D2608
Objective-C literals to bool conversion warning rtrieu on Jan 23 2014, 2:43 PM. Authored by
Details
Warn when a Objective-C literal is converted to a boolean. This warns on NSNumber*, NSString*, NSArray* and NSDictionary* literals. Excludes objc_yes and objc_no. I don't normally work with Objective-C so let me know if I am missing any test cases.
Diff Detail Event TimelineComment Actions Huh, I thought we already had a check for this. This seems fine, but we might as well test every Objective-C literal type. None of them can evaluate to nil...and then I'd rather group the @"" conversion with those, rather than -Wstring-conversion. Comment Actions Besides strings, anything on this page: http://clang.llvm.org/docs/ObjectiveCLiterals.html That corresponds to ObjCStringLiteral, ObjCBoxedExpr, ObjCArrayLiteral, and ObjCDictionaryLiteral...but not ObjCBoolLiteral (which is just __objc_yes and __objc_no). -Wobjc-literal-conversion, perhaps? (I suppose you could throw ObjCSelectorExpr in there as well, though that one probably deserves custom text; the others are all "Objective-C object literals". ObjCEncodeExpr just expands to a C string, so that could go under -Wstring-conversion if you cared.) Comment Actions Remember, "Objective-C" is always hyphenated. :-)
Comment Actions Justification for dropping the "boolean" in "implicit boolean conversion"? I'm worried that a non-compiler-writer looking at the code won't see where the conversion is. (I didn't phrase it as "conversion...to bool" because Objective-C programmers don't usually think about "bool", even though they're probably compiling in gnu99 mode.) Comment Actions
Oops, dropped it while copying the text. I'll go fix the text. Comment Actions Committed at r200356. Switched to on by default instead of DefaultIgnore. One analysis test required disabling this warning. |
There are a lot of "Objective-C types". How about "This covers the literal expressions that evaluate to Objective-C objects"?