Open llvmbot opened 10 years ago
r200356 now makes Clang catch Objective-C object literal to bool conversions. On by default, or use -Wobjc-literal-conversion. So this will warn on the example of:
if (@"blabla")
http://llvm-reviews.chandlerc.com/D2608
This is a patch to extend -Wstring-conversion to catch "if(@"blabla")"
shouldn't Wstring-conversion also catch the second case?
"Due to that, -Wstring-conversion will warn when a string literal is converted to a true boolean value. "
only works for C strings and not ObjC strings?
Wouldn't this be better suited for a compiler warning?
The static analyzer isn't usually very good at answering questions that are true on /all/ paths; it's better at finding /any/ path. But we can probably contrive a way to handle the first case, and the second case could probably be implemented just with the constant evaluator.
assigned to @tkremenek
Extended Description
static NSString *const bla = @"bla";
if (bla) NSLog(@"always true");
if (@"blabla") NSLog(@"always true");
both conditions don't generate a warning with clang even with -Weverything and even the static analyzer doesn't complain although the conditions are bound to be always true.