A new conversion warning for when an Objective-C object literal is implicitly
cast into a boolean true value. This warning will catch code like:
if (@0) {}
if (@"foo") {}
llvm-svn: 200356
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 0dffa53..ee0e670 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -5358,6 +5358,13 @@
// prevented by a check in AnalyzeImplicitConversions().
return DiagnoseImpCast(S, E, T, CC,
diag::warn_impcast_string_literal_to_bool);
+ if (isa<ObjCStringLiteral>(E) || isa<ObjCArrayLiteral>(E) ||
+ isa<ObjCDictionaryLiteral>(E) || isa<ObjCBoxedExpr>(E)) {
+ // This covers the literal expressions that evaluate to Objective-C
+ // objects.
+ return DiagnoseImpCast(S, E, T, CC,
+ diag::warn_impcast_objective_c_literal_to_bool);
+ }
if (Source->isFunctionType()) {
// Warn on function to bool. Checks free functions and static member
// functions. Weakly imported functions are excluded from the check,