[PATCH] Objective C literals to bool conversion warning

Jordan Rose jordan_rose at apple.com
Tue Jan 28 09:14:22 PST 2014


  Remember, "Objective-C" is always hyphenated. :-)


================
Comment at: include/clang/Basic/DiagnosticSemaKinds.td:2299-2301
@@ -2298,2 +2298,5 @@
     "suffix with parentheses to turn this into a function call">;
+def warn_impcast_objective_c_literal_to_bool : Warning<
+    "implicit conversion turns Objective C literal into bool: %0 to %1">,
+    InGroup<ObjCLiteralConversion>, DefaultIgnore;
 
----------------
Ideally I'd like something more like "implicit boolean conversion of %select{array literal|dictionary literal|numeric literal|boxed expression}0 always evaluates to true". Failing that, let's go with "Objective-C object literal".

================
Comment at: lib/Sema/SemaChecking.cpp:5355-5356
@@ +5354,4 @@
+        isa<ObjCDictionaryLiteral>(E) || isa<ObjCBoxedExpr>(E)) {
+      // Warn on Objective C literal to bool conversions.  This covers most of
+      // the Objective C types, except for ObjCBoolLiteral.
+      return DiagnoseImpCast(S, E, T, CC,
----------------
There are a lot of "Objective-C types". How about "This covers the literal expressions that evaluate to Objective-C objects"?


http://llvm-reviews.chandlerc.com/D2608



More information about the cfe-commits mailing list