1 // RUN: %clang_cc1 -fsyntax-only -fobjc-runtime-has-weak -fobjc-arc -fblocks -Wno-objc-root-class -Wreceiver-is-weak -verify %s
5 - (void) setBlock: (void(^)(void)) block;
6 - (void) addBlock: (void(^)(void)) block;
10 void test0(Test0 *x) {
11 __weak Test0 *weakx = x;
12 [x addBlock: ^{ [weakx actNow]; }]; // expected-warning {{weak receiver may be unpredictably set to nil}} expected-note {{assign the value to a strong variable to keep the object alive during use}}
13 [x setBlock: ^{ [weakx actNow]; }]; // expected-warning {{weak receiver may be unpredictably set to nil}} expected-note {{assign the value to a strong variable to keep the object alive during use}}
14 x.block = ^{ [weakx actNow]; }; // expected-warning {{weak receiver may be unpredictably set to nil}} expected-note {{assign the value to a strong variable to keep the object alive during use}}
16 [weakx addBlock: ^{ [x actNow]; }]; // expected-warning {{weak receiver may be unpredictably set to nil}} expected-note {{assign the value to a strong variable to keep the object alive during use}}
17 [weakx setBlock: ^{ [x actNow]; }]; // expected-warning {{weak receiver may be unpredictably set to nil}} expected-note {{assign the value to a strong variable to keep the object alive during use}}
18 weakx.block = ^{ [x actNow]; }; // expected-warning {{weak receiver may be unpredictably set to nil}} expected-note {{assign the value to a strong variable to keep the object alive during use}}
23 __weak Test* weak_prop;
26 @property __weak Test* weak_prop; // expected-note {{property declared here}}
27 @property (weak, atomic) id weak_atomic_prop; // expected-note {{property declared here}}
28 - (__weak id) P; // expected-note {{method 'P' declared here}}
36 if (self.weak_atomic_prop) {
37 self.weak_atomic_prop = 0;
39 [self.weak_prop Meth]; // expected-warning {{weak property may be unpredictably set to nil}} expected-note {{assign the value to a strong variable to keep the object alive during use}}
42 [self.weak_atomic_prop Meth]; // expected-warning {{weak property may be unpredictably set to nil}} expected-note {{assign the value to a strong variable to keep the object alive during use}}
44 [self.P Meth]; // expected-warning {{weak implicit property may be unpredictably set to nil}} expected-note {{assign the value to a strong variable to keep the object alive during use}}
47 - (__weak id) P { return 0; }
48 @dynamic weak_prop, weak_atomic_prop;
53 __weak MyClass *_parent;
55 @property (weak) MyClass *parent; // expected-note 4 {{property declared here}}
58 @implementation MyClass
59 @synthesize parent = _parent;
63 [[self parent] doSomething]; // expected-warning {{weak property may be unpredictably set to nil}} expected-note {{assign the value to a strong variable to keep the object alive during use}}
65 (void)self.parent.doSomething; // expected-warning {{weak property may be unpredictably set to nil}} expected-note {{assign the value to a strong variable to keep the object alive during use}}
71 // Weak properties on protocols can be synthesized by an adopting class.
73 @property (weak) id object; // expected-note 2 {{property declared here}}
76 void testProtocol(id <MyProtocol> input) {
77 [[input object] Meth]; // expected-warning {{weak property may be unpredictably set to nil}} expected-note {{assign the value to a strong variable to keep the object alive during use}}
78 [input.object Meth]; // expected-warning {{weak property may be unpredictably set to nil}} expected-note {{assign the value to a strong variable to keep the object alive during use}}
82 @interface Subclass : MyClass
83 // Unnecessarily redeclare -parent.
87 @implementation Subclass
90 return [super parent];
93 - (void)doSomethingElse {
94 [[self parent] doSomething]; // expected-warning {{weak property may be unpredictably set to nil}} expected-note {{assign the value to a strong variable to keep the object alive during use}}
96 (void)self.parent.doSomething; // expected-warning {{weak property may be unpredictably set to nil}} expected-note {{assign the value to a strong variable to keep the object alive during use}}