summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaChecking.cpp
diff options
context:
space:
mode:
authorRichard Trieu <rtrieu@google.com>2014-01-28 23:40:26 +0000
committerRichard Trieu <rtrieu@google.com>2014-01-28 23:40:26 +0000
commit1e632af0d4989357836a52ff8a0e237e69ca81d3 (patch)
tree7eb2d52f01f30076c258c7459197eb8a99f24f4d /clang/lib/Sema/SemaChecking.cpp
parenta86694ca7a25d299d015c62cd711c46dc8bc563a (diff)
downloadbcm5719-llvm-1e632af0d4989357836a52ff8a0e237e69ca81d3.tar.gz
bcm5719-llvm-1e632af0d4989357836a52ff8a0e237e69ca81d3.zip
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
Diffstat (limited to 'clang/lib/Sema/SemaChecking.cpp')
-rw-r--r--clang/lib/Sema/SemaChecking.cpp7
1 files changed, 7 insertions, 0 deletions
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 0dffa53679e..ee0e6702e0f 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -5358,6 +5358,13 @@ void CheckImplicitConversion(Sema &S, Expr *E, QualType T,
// 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,
OpenPOWER on IntegriCloud