aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2012-12-20 20:55:03 +0000
committerTed Kremenek <kremenek@apple.com>2012-12-20 20:55:03 +0000
commit7c441069a41e164498047aaed542d0d64bc11962 (patch)
tree6a63262ce9cb3185116c7bba59f4517d51faa9fe /test
parent7b00b84752b7f3cbd4079f88ddb359170b7073c1 (diff)
Warn if a __weak variable is initialized with an Objective-C object literal.
Such variables may immediately become nil or may have unpredictable behavior. Fixes <rdar://problem/12569201>. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@170763 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test')
-rw-r--r--test/SemaObjC/arc.m24
1 files changed, 24 insertions, 0 deletions
diff --git a/test/SemaObjC/arc.m b/test/SemaObjC/arc.m
index bd30715a6b..c6cb88c645 100644
--- a/test/SemaObjC/arc.m
+++ b/test/SemaObjC/arc.m
@@ -4,6 +4,21 @@ typedef unsigned long NSUInteger;
typedef const void * CFTypeRef;
CFTypeRef CFBridgingRetain(id X);
id CFBridgingRelease(CFTypeRef);
+@protocol NSCopying @end
+@interface NSDictionary
++ (id)dictionaryWithObjects:(const id [])objects forKeys:(const id <NSCopying> [])keys count:(NSUInteger)cnt;
+- (void)setObject:(id)object forKeyedSubscript:(id)key;
+@end
+@class NSFastEnumerationState;
+@protocol NSFastEnumeration
+- (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id [])buffer count:(NSUInteger)len;
+@end
+@interface NSNumber
++ (NSNumber *)numberWithInt:(int)value;
+@end
+@interface NSArray <NSFastEnumeration>
++ (id)arrayWithObjects:(const id [])objects count:(NSUInteger)cnt;
+@end
void test0(void (*fn)(int), int val) {
fn(val);
@@ -717,3 +732,12 @@ void _NSCalcBeze(NSColor* color, NSColor* bezelColors[]); // expected-error {{mu
- init { return 0; }
@end
+// <rdar://problem/12569201>. Warn on cases of initializing a weak variable
+// with an Objective-C object literal.
+void rdar12569201(id key, id value) {
+ __weak id x = @"foo"; // expected-warning {{__weak variable initialized with an object literal may immediately become nil}}
+ __weak id y = @{ key : value }; // expected-warning {{__weak variable initialized with an object literal may immediately become nil}}
+ __weak id z = @[ value ]; // expected-warning {{__weak variable initialized with an object literal may immediately become nil}}
+ __weak id b = ^() {}; // expected-warning {{__weak variable initialized with an object literal may immediately become nil}}
+ __weak __block id b2 = ^() {}; // expected-warning {{__weak variable initialized with an object literal may immediately become nil}}
+}