aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJordan Rose <jordan_rose@apple.com>2012-07-17 17:46:48 +0000
committerJordan Rose <jordan_rose@apple.com>2012-07-17 17:46:48 +0000
commitd5209ae13a7c42e2b7fa641f75a66e545959cbed (patch)
tree980312ff8d6ec328ad4b415ebea8adf638b6d299 /test
parenteec207f02a0208814bb8b4ca90099a2fed016244 (diff)
-Wobjc-literal-compare: don't warn when comparing against nil.
Checks against nil often appear as guards in macros, and comparing Objective-C literals to nil has well-defined behavior (if tautological). On OS X, 'nil' has not been typed as 'id' since 10.6 (possibly earlier), so the warning was already not firing, but other runtimes continue to use ((id)0) or some variant. This change accepts comparisons to any null pointer; to keep it simple, it looks through all casts (not just casts to 'id'). PR13276 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@160379 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test')
-rw-r--r--test/SemaObjC/objc-literal-comparison.m19
1 files changed, 17 insertions, 2 deletions
diff --git a/test/SemaObjC/objc-literal-comparison.m b/test/SemaObjC/objc-literal-comparison.m
index ea42a176ef..f1aa8ecd91 100644
--- a/test/SemaObjC/objc-literal-comparison.m
+++ b/test/SemaObjC/objc-literal-comparison.m
@@ -1,8 +1,10 @@
-// RUN: %clang_cc1 -fsyntax-only -Wno-everything -Wobjc-literal-compare -verify %s
+// RUN: %clang_cc1 -fsyntax-only -Wno-everything -Wobjc-literal-compare "-Dnil=((id)0)" -verify %s
+// RUN: %clang_cc1 -fsyntax-only -Wno-everything -Wobjc-literal-compare "-Dnil=(id)0" -verify %s
+// RUN: %clang_cc1 -fsyntax-only -Wno-everything -Wobjc-literal-compare "-Dnil=0" -verify %s
// (test the warning flag as well)
-typedef unsigned char BOOL;
+typedef signed char BOOL;
@interface BaseObject
+ (instancetype)new;
@@ -79,3 +81,16 @@ void testWarningFlags(id obj) {
#pragma clang diagnostic pop
+
+void testNilComparison() {
+ // Don't warn when comparing to nil in a macro.
+#define RETURN_IF_NIL(x) if (x == nil || nil == x) return
+ RETURN_IF_NIL(@"");
+ RETURN_IF_NIL(@1);
+ RETURN_IF_NIL(@1.0);
+ RETURN_IF_NIL(@[]);
+ RETURN_IF_NIL(@{});
+ RETURN_IF_NIL(@__objc_yes);
+ RETURN_IF_NIL(@(1+1));
+}
+