xref: /aosp_15_r20/external/clang/test/SemaObjC/arc.m (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fobjc-runtime-has-weak -fsyntax-only -fobjc-arc -fblocks -verify -Wno-objc-root-class %s
2*67e74705SXin Li
3*67e74705SXin Litypedef unsigned long NSUInteger;
4*67e74705SXin Litypedef const void * CFTypeRef;
5*67e74705SXin LiCFTypeRef CFBridgingRetain(id X);
6*67e74705SXin Liid CFBridgingRelease(CFTypeRef);
7*67e74705SXin Li@protocol NSCopying @end
8*67e74705SXin Li@interface NSDictionary
9*67e74705SXin Li+ (id)dictionaryWithObjects:(const id [])objects forKeys:(const id <NSCopying> [])keys count:(NSUInteger)cnt;
10*67e74705SXin Li- (void)setObject:(id)object forKeyedSubscript:(id)key;
11*67e74705SXin Li@end
12*67e74705SXin Li@class NSFastEnumerationState;
13*67e74705SXin Li@protocol NSFastEnumeration
14*67e74705SXin Li- (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id __unsafe_unretained [])buffer count:(NSUInteger)len;
15*67e74705SXin Li@end
16*67e74705SXin Li@interface NSNumber
17*67e74705SXin Li+ (NSNumber *)numberWithInt:(int)value;
18*67e74705SXin Li@end
19*67e74705SXin Li@interface NSArray <NSFastEnumeration>
20*67e74705SXin Li+ (id)arrayWithObjects:(const id [])objects count:(NSUInteger)cnt;
21*67e74705SXin Li@end
22*67e74705SXin Li
23*67e74705SXin Livoid test0(void (*fn)(int), int val) {
24*67e74705SXin Li  fn(val);
25*67e74705SXin Li}
26*67e74705SXin Li
27*67e74705SXin Li@interface A
28*67e74705SXin Li- (id)retain;
29*67e74705SXin Li- (id)autorelease;
30*67e74705SXin Li- (oneway void)release;
31*67e74705SXin Li- (void)dealloc;
32*67e74705SXin Li- (NSUInteger)retainCount;
33*67e74705SXin Li@end
34*67e74705SXin Li
35*67e74705SXin Livoid test1(A *a) {
36*67e74705SXin Li  SEL s = @selector(retain);	// expected-error {{ARC forbids use of 'retain' in a @selector}}
37*67e74705SXin Li  s = @selector(release);	// expected-error {{ARC forbids use of 'release' in a @selector}}
38*67e74705SXin Li  s = @selector(autorelease);	// expected-error {{ARC forbids use of 'autorelease' in a @selector}}
39*67e74705SXin Li  s = @selector(dealloc);	// expected-error {{ARC forbids use of 'dealloc' in a @selector}}
40*67e74705SXin Li  [a dealloc]; // expected-error {{ARC forbids explicit message send of 'dealloc'}}
41*67e74705SXin Li  [a retain]; // expected-error {{ARC forbids explicit message send of 'retain'}}
42*67e74705SXin Li  [a retainCount]; // expected-error {{ARC forbids explicit message send of 'retainCount'}}
43*67e74705SXin Li  [a release]; // expected-error {{ARC forbids explicit message send of 'release'}}
44*67e74705SXin Li  [a autorelease]; // expected-error {{ARC forbids explicit message send of 'autorelease'}}
45*67e74705SXin Li}
46*67e74705SXin Li
47*67e74705SXin Li@interface Test2 : A
48*67e74705SXin Li- (void) dealloc;
49*67e74705SXin Li@end
50*67e74705SXin Li@implementation Test2
51*67e74705SXin Li- (void) dealloc {
52*67e74705SXin Li  // This should maybe just be ignored.  We're just going to warn about it for now.
53*67e74705SXin Li  [super dealloc]; // expected-error {{ARC forbids explicit message send of 'dealloc'}}
54*67e74705SXin Li}
55*67e74705SXin Li@end
56*67e74705SXin Li
57*67e74705SXin Li// rdar://8843638
58*67e74705SXin Li
59*67e74705SXin Li@interface I
60*67e74705SXin Li- (id)retain; // expected-note {{method 'retain' declared here}}
61*67e74705SXin Li- (id)autorelease; // expected-note {{method 'autorelease' declared here}}
62*67e74705SXin Li- (oneway void)release; // expected-note {{method 'release' declared here}}
63*67e74705SXin Li- (NSUInteger)retainCount; // expected-note {{method 'retainCount' declared here}}
64*67e74705SXin Li@end
65*67e74705SXin Li
66*67e74705SXin Li@implementation I
67*67e74705SXin Li- (id)retain{return 0;} // expected-error {{ARC forbids implementation of 'retain'}}
68*67e74705SXin Li- (id)autorelease{return 0;} // expected-error {{ARC forbids implementation of 'autorelease'}}
69*67e74705SXin Li- (oneway void)release{} // expected-error {{ARC forbids implementation of 'release'}}
70*67e74705SXin Li- (NSUInteger)retainCount{ return 0; } // expected-error {{ARC forbids implementation of 'retainCount'}}
71*67e74705SXin Li@end
72*67e74705SXin Li
73*67e74705SXin Li@implementation I(CAT)
74*67e74705SXin Li- (id)retain{return 0;} // expected-error {{ARC forbids implementation of 'retain'}} \
75*67e74705SXin Li                        // expected-warning {{category is implementing a method which will also be implemented by its primary class}}
76*67e74705SXin Li- (id)autorelease{return 0;} // expected-error {{ARC forbids implementation of 'autorelease'}} \
77*67e74705SXin Li                         // expected-warning {{category is implementing a method which will also be implemented by its primary class}}
78*67e74705SXin Li- (oneway void)release{} // expected-error {{ARC forbids implementation of 'release'}} \
79*67e74705SXin Li                          // expected-warning {{category is implementing a method which will also be implemented by its primary class}}
80*67e74705SXin Li- (NSUInteger)retainCount{ return 0; } // expected-error {{ARC forbids implementation of 'retainCount'}} \
81*67e74705SXin Li                          // expected-warning {{category is implementing a method which will also be implemented by its primary class}}
82*67e74705SXin Li@end
83*67e74705SXin Li
84*67e74705SXin Li// rdar://8861761
85*67e74705SXin Li
86*67e74705SXin Li@interface B
87*67e74705SXin Li+ (id)alloc;
88*67e74705SXin Li- (id)initWithInt: (int) i;
89*67e74705SXin Li- (id)myInit __attribute__((objc_method_family(init)));
90*67e74705SXin Li- (id)myBadInit __attribute__((objc_method_family(12)));  // expected-error {{'objc_method_family' attribute requires parameter 1 to be an identifier}}
91*67e74705SXin Li
92*67e74705SXin Li@end
93*67e74705SXin Li
94*67e74705SXin Livoid rdar8861761() {
95*67e74705SXin Li  B *o1 = [[B alloc] initWithInt:0];
96*67e74705SXin Li  B *o2 = [B alloc];
97*67e74705SXin Li  [o2 initWithInt:0]; // expected-warning {{expression result unused}}
98*67e74705SXin Li  B *o3 = [[B alloc] myInit];
99*67e74705SXin Li  [[B alloc] myInit]; // expected-warning {{expression result unused}}
100*67e74705SXin Li}
101*67e74705SXin Li
102*67e74705SXin Li// rdar://8925835
103*67e74705SXin Li@interface rdar8925835
104*67e74705SXin Li- (void)foo:(void (^)(unsigned captureCount, I * const capturedStrings[captureCount]))block;
105*67e74705SXin Li@end
106*67e74705SXin Li
107*67e74705SXin Livoid test5() {
108*67e74705SXin Li  extern void test5_helper(__autoreleasing id *);
109*67e74705SXin Li  id x;
110*67e74705SXin Li
111*67e74705SXin Li  // Okay because of magic temporaries.
112*67e74705SXin Li  test5_helper(&x);
113*67e74705SXin Li
114*67e74705SXin Li  __autoreleasing id *a = &x; // expected-error {{initializing '__autoreleasing id *' with an expression of type '__strong id *' changes retain/release properties of pointer}}
115*67e74705SXin Li
116*67e74705SXin Li  a = &x; // expected-error {{assigning '__strong id *' to '__autoreleasing id *' changes retain/release properties of pointer}}
117*67e74705SXin Li
118*67e74705SXin Li  extern void test5_helper2(id const *);
119*67e74705SXin Li  test5_helper2(&x);
120*67e74705SXin Li
121*67e74705SXin Li  extern void test5_helper3(__weak id *); // expected-note {{passing argument to parameter here}}
122*67e74705SXin Li  test5_helper3(&x); // expected-error {{passing '__strong id *' to parameter of type '__weak id *' changes retain/release properties of pointer}}
123*67e74705SXin Li}
124*67e74705SXin Li
125*67e74705SXin Li// rdar://problem/8937869
126*67e74705SXin Livoid test6(unsigned cond) {
127*67e74705SXin Li  switch (cond) {
128*67e74705SXin Li  case 0:
129*67e74705SXin Li    ;
130*67e74705SXin Li    id x; // expected-note {{jump bypasses initialization of __strong variable}}
131*67e74705SXin Li
132*67e74705SXin Li  case 1: // expected-error {{cannot jump}}
133*67e74705SXin Li    break;
134*67e74705SXin Li  }
135*67e74705SXin Li}
136*67e74705SXin Livoid test6a(unsigned cond) {
137*67e74705SXin Li  switch (cond) {
138*67e74705SXin Li  case 0:
139*67e74705SXin Li    ;
140*67e74705SXin Li    __weak id x; // expected-note {{jump bypasses initialization of __weak variable}}
141*67e74705SXin Li
142*67e74705SXin Li  case 1: // expected-error {{cannot jump}}
143*67e74705SXin Li    break;
144*67e74705SXin Li  }
145*67e74705SXin Li}
146*67e74705SXin Li
147*67e74705SXin Li@class NSError;
148*67e74705SXin Livoid test7(void) {
149*67e74705SXin Li  extern void test7_helper(NSError **);
150*67e74705SXin Li  NSError *err;
151*67e74705SXin Li  test7_helper(&err);
152*67e74705SXin Li}
153*67e74705SXin Livoid test7_weak(void) {
154*67e74705SXin Li  extern void test7_helper(NSError **);
155*67e74705SXin Li  __weak NSError *err;
156*67e74705SXin Li  test7_helper(&err);
157*67e74705SXin Li}
158*67e74705SXin Livoid test7_unsafe(void) {
159*67e74705SXin Li  extern void test7_helper(NSError **); // expected-note {{passing argument to parameter here}}
160*67e74705SXin Li  __unsafe_unretained NSError *err;
161*67e74705SXin Li  test7_helper(&err); // expected-error {{passing 'NSError *__unsafe_unretained *' to parameter of type 'NSError *__autoreleasing *' changes retain/release properties of pointer}}
162*67e74705SXin Li}
163*67e74705SXin Li
164*67e74705SXin Li@class Test8_incomplete;
165*67e74705SXin Li@interface Test8_complete @end;
166*67e74705SXin Li@interface Test8_super @end;
167*67e74705SXin Li@interface Test8 : Test8_super
168*67e74705SXin Li- (id) init00;
169*67e74705SXin Li- (id) init01; // expected-note {{declaration in interface}} \
170*67e74705SXin Li               // expected-note{{overridden method}}
171*67e74705SXin Li- (id) init02; // expected-note{{overridden method}}
172*67e74705SXin Li- (id) init03; // covariance
173*67e74705SXin Li- (id) init04; // covariance
174*67e74705SXin Li- (id) init05; // expected-note{{overridden method}}
175*67e74705SXin Li
176*67e74705SXin Li- (void) init10; // expected-note {{declaration in interface is not in the 'init' family because its result type is not an object pointer}}
177*67e74705SXin Li- (void) init11;
178*67e74705SXin Li- (void) init12;
179*67e74705SXin Li- (void) init13; // expected-note {{declaration in interface is not in the 'init' family because its result type is not an object pointer}}
180*67e74705SXin Li- (void) init14; // expected-note {{declaration in interface is not in the 'init' family because its result type is not an object pointer}}
181*67e74705SXin Li- (void) init15;
182*67e74705SXin Li
183*67e74705SXin Li// These should be invalid to actually call.
184*67e74705SXin Li- (Test8_incomplete*) init20;
185*67e74705SXin Li- (Test8_incomplete*) init21; // expected-note {{declaration in interface}}
186*67e74705SXin Li- (Test8_incomplete*) init22;
187*67e74705SXin Li- (Test8_incomplete*) init23;
188*67e74705SXin Li- (Test8_incomplete*) init24;
189*67e74705SXin Li- (Test8_incomplete*) init25;
190*67e74705SXin Li
191*67e74705SXin Li- (Test8_super*) init30; // id exception to covariance
192*67e74705SXin Li- (Test8_super*) init31; // expected-note {{declaration in interface}} \
193*67e74705SXin Li                         // expected-note{{overridden method}}
194*67e74705SXin Li- (Test8_super*) init32; // expected-note{{overridden method}}
195*67e74705SXin Li- (Test8_super*) init33;
196*67e74705SXin Li- (Test8_super*) init34; // covariance
197*67e74705SXin Li- (Test8_super*) init35; // expected-note{{overridden method}}
198*67e74705SXin Li
199*67e74705SXin Li- (Test8*) init40; // id exception to covariance
200*67e74705SXin Li- (Test8*) init41; // expected-note {{declaration in interface}} \
201*67e74705SXin Li                   // expected-note{{overridden method}}
202*67e74705SXin Li- (Test8*) init42; // expected-note{{overridden method}}
203*67e74705SXin Li- (Test8*) init43; // this should be a warning, but that's a general language thing, not an ARC thing
204*67e74705SXin Li- (Test8*) init44;
205*67e74705SXin Li- (Test8*) init45; // expected-note{{overridden method}}
206*67e74705SXin Li
207*67e74705SXin Li- (Test8_complete*) init50; // expected-error {{init methods must return a type related to the receiver type}}
208*67e74705SXin Li- (Test8_complete*) init51; // expected-error {{init methods must return a type related to the receiver type}}
209*67e74705SXin Li- (Test8_complete*) init52; // expected-error {{init methods must return a type related to the receiver type}}
210*67e74705SXin Li- (Test8_complete*) init53; // expected-error {{init methods must return a type related to the receiver type}}
211*67e74705SXin Li- (Test8_complete*) init54; // expected-error {{init methods must return a type related to the receiver type}}
212*67e74705SXin Li- (Test8_complete*) init55; // expected-error {{init methods must return a type related to the receiver type}}
213*67e74705SXin Li@end
214*67e74705SXin Li@implementation Test8
215*67e74705SXin Li- (id) init00 { return 0; }
216*67e74705SXin Li- (id) init10 { return 0; } // expected-error {{method implementation does not match its declaration}}
217*67e74705SXin Li- (id) init20 { return 0; }
218*67e74705SXin Li- (id) init30 { return 0; }
219*67e74705SXin Li- (id) init40 { return 0; }
220*67e74705SXin Li- (id) init50 { return 0; }
221*67e74705SXin Li
222*67e74705SXin Li- (void) init01 {} // expected-error {{method was declared as an 'init' method, but its implementation doesn't match because its result type is not an object pointer}} \
223*67e74705SXin Li                   // expected-warning{{method is expected to return an instance of its class type 'Test8', but is declared to return 'void'}}
224*67e74705SXin Li- (void) init11 {}
225*67e74705SXin Li- (void) init21 {} // expected-error {{method was declared as an 'init' method, but its implementation doesn't match because its result type is not an object pointer}}
226*67e74705SXin Li- (void) init31 {} // expected-error {{method was declared as an 'init' method, but its implementation doesn't match because its result type is not an object pointer}} \
227*67e74705SXin Li                   // expected-warning{{method is expected to return an instance of its class type 'Test8', but is declared to return 'void'}}
228*67e74705SXin Li- (void) init41 {} // expected-error {{method was declared as an 'init' method, but its implementation doesn't match because its result type is not an object pointer}} \
229*67e74705SXin Li                   // expected-warning{{method is expected to return an instance of its class type 'Test8', but is declared to return 'void'}}
230*67e74705SXin Li- (void) init51 {}
231*67e74705SXin Li
232*67e74705SXin Li- (Test8_incomplete*) init02 { return 0; } // expected-error {{init methods must return a type related to the receiver type}} \
233*67e74705SXin Li                                           // expected-warning{{method is expected to return an instance of its class type 'Test8', but is declared to return 'Test8_incomplete *'}}
234*67e74705SXin Li- (Test8_incomplete*) init12 { return 0; } // expected-error {{init methods must return a type related to the receiver type}}
235*67e74705SXin Li- (Test8_incomplete*) init22 { return 0; } // expected-error {{init methods must return a type related to the receiver type}}
236*67e74705SXin Li- (Test8_incomplete*) init32 { return 0; } // expected-error {{init methods must return a type related to the receiver type}} \
237*67e74705SXin Li                                           // expected-warning{{method is expected to return an instance of its class type 'Test8', but is declared to return 'Test8_incomplete *'}}
238*67e74705SXin Li- (Test8_incomplete*) init42 { return 0; } // expected-error {{init methods must return a type related to the receiver type}} \
239*67e74705SXin Li                                           // expected-warning{{method is expected to return an instance of its class type 'Test8', but is declared to return 'Test8_incomplete *'}}
240*67e74705SXin Li- (Test8_incomplete*) init52 { return 0; } // expected-error {{init methods must return a type related to the receiver type}}
241*67e74705SXin Li
242*67e74705SXin Li- (Test8_super*) init03 { return 0; }
243*67e74705SXin Li- (Test8_super*) init13 { return 0; } // expected-error {{method implementation does not match its declaration}}
244*67e74705SXin Li- (Test8_super*) init23 { return 0; }
245*67e74705SXin Li- (Test8_super*) init33 { return 0; }
246*67e74705SXin Li- (Test8_super*) init43 { return 0; }
247*67e74705SXin Li- (Test8_super*) init53 { return 0; }
248*67e74705SXin Li
249*67e74705SXin Li- (Test8*) init04 { return 0; }
250*67e74705SXin Li- (Test8*) init14 { return 0; } // expected-error {{method implementation does not match its declaration}}
251*67e74705SXin Li- (Test8*) init24 { return 0; }
252*67e74705SXin Li- (Test8*) init34 { return 0; }
253*67e74705SXin Li- (Test8*) init44 { return 0; }
254*67e74705SXin Li- (Test8*) init54 { return 0; }
255*67e74705SXin Li
256*67e74705SXin Li- (Test8_complete*) init05 { return 0; } // expected-error {{init methods must return a type related to the receiver type}} \
257*67e74705SXin Li                                         // expected-warning{{method is expected to return an instance of its class type 'Test8', but is declared to return 'Test8_complete *'}}
258*67e74705SXin Li- (Test8_complete*) init15 { return 0; } // expected-error {{init methods must return a type related to the receiver type}}
259*67e74705SXin Li- (Test8_complete*) init25 { return 0; } // expected-error {{init methods must return a type related to the receiver type}}
260*67e74705SXin Li- (Test8_complete*) init35 { return 0; } // expected-error {{init methods must return a type related to the receiver type}} \
261*67e74705SXin Li                                         // expected-warning{{method is expected to return an instance of its class type 'Test8', but is declared to return 'Test8_complete *'}}
262*67e74705SXin Li- (Test8_complete*) init45 { return 0; } // expected-error {{init methods must return a type related to the receiver type}} \
263*67e74705SXin Li                                         // expected-warning{{method is expected to return an instance of its class type 'Test8', but is declared to return 'Test8_complete *'}}
264*67e74705SXin Li- (Test8_complete*) init55 { return 0; } // expected-error {{init methods must return a type related to the receiver type}}
265*67e74705SXin Li@end
266*67e74705SXin Li
267*67e74705SXin Li@class Test9_incomplete;
268*67e74705SXin Li@interface Test9
269*67e74705SXin Li- (Test9_incomplete*) init1; // expected-error {{init methods must return a type related to the receiver type}}
270*67e74705SXin Li- (Test9_incomplete*) init2;
271*67e74705SXin Li@end
272*67e74705SXin Liid test9(Test9 *v) {
273*67e74705SXin Li  return [v init1];
274*67e74705SXin Li}
275*67e74705SXin Li
276*67e74705SXin Li// Test that the inference rules are different for fast enumeration variables.
277*67e74705SXin Livoid test10(id collection) {
278*67e74705SXin Li  for (id x in collection) {
279*67e74705SXin Li    __strong id *ptr = &x; // expected-warning {{initializing '__strong id *' with an expression of type 'const __strong id *' discards qualifiers}}
280*67e74705SXin Li  }
281*67e74705SXin Li
282*67e74705SXin Li  for (__strong id x in collection) {
283*67e74705SXin Li    __weak id *ptr = &x; // expected-error {{initializing '__weak id *' with an expression of type '__strong id *' changes retain/release properties of pointer}}
284*67e74705SXin Li  }
285*67e74705SXin Li}
286*67e74705SXin Li
287*67e74705SXin Li// rdar://problem/9078626
288*67e74705SXin Li#define nil ((void*) 0)
289*67e74705SXin Livoid test11(id op, void *vp) {
290*67e74705SXin Li  _Bool b;
291*67e74705SXin Li  b = (op == nil);
292*67e74705SXin Li  b = (nil == op);
293*67e74705SXin Li
294*67e74705SXin Li  b = (vp == nil);
295*67e74705SXin Li  b = (nil == vp);
296*67e74705SXin Li
297*67e74705SXin Li  b = (vp == op); // expected-error {{implicit conversion of Objective-C pointer type 'id' to C pointer type 'void *' requires a bridged cast}} expected-note {{use __bridge}} expected-note {{use CFBridgingRetain call}}
298*67e74705SXin Li  b = (op == vp);
299*67e74705SXin Li}
300*67e74705SXin Li
301*67e74705SXin Livoid test12(id collection) {
302*67e74705SXin Li  for (id x in collection) {
303*67e74705SXin Li    x = 0; // expected-error {{fast enumeration variables cannot be modified in ARC by default; declare the variable __strong to allow this}}
304*67e74705SXin Li  }
305*67e74705SXin Li
306*67e74705SXin Li  for (const id x in collection) { // expected-note {{variable 'x' declared const here}}
307*67e74705SXin Li    x = 0; // expected-error {{cannot assign to variable 'x' with const-qualified type 'const __strong id'}}
308*67e74705SXin Li  }
309*67e74705SXin Li
310*67e74705SXin Li  for (__strong id x in collection) {
311*67e74705SXin Li    x = 0;
312*67e74705SXin Li  }
313*67e74705SXin Li}
314*67e74705SXin Li
315*67e74705SXin Li@interface Test13
316*67e74705SXin Li- (id) init0;
317*67e74705SXin Li- (void) noninit;
318*67e74705SXin Li@end
319*67e74705SXin Li@implementation Test13
320*67e74705SXin Li- (id) init0 {
321*67e74705SXin Li  self = 0;
322*67e74705SXin Li}
323*67e74705SXin Li- (void) noninit {
324*67e74705SXin Li  self = 0; // expected-error {{cannot assign to 'self' outside of a method in the init family}}
325*67e74705SXin Li}
326*67e74705SXin Li@end
327*67e74705SXin Li
328*67e74705SXin Li// <rdar://problem/10274056>
329*67e74705SXin Li@interface Test13_B
330*67e74705SXin Li- (id) consumesSelf __attribute__((ns_consumes_self));
331*67e74705SXin Li@end
332*67e74705SXin Li@implementation Test13_B
333*67e74705SXin Li- (id) consumesSelf {
334*67e74705SXin Li  self = 0; // no-warning
335*67e74705SXin Li}
336*67e74705SXin Li@end
337*67e74705SXin Li
338*67e74705SXin Li// rdar://problem/9172151
339*67e74705SXin Li@class Test14A, Test14B;
340*67e74705SXin Livoid test14() {
341*67e74705SXin Li  extern void test14_consume(id *);
342*67e74705SXin Li  extern int test14_cond(void);
343*67e74705SXin Li  extern float test14_nowriteback(id __autoreleasing const *); // expected-note{{passing argument to parameter here}}
344*67e74705SXin Li
345*67e74705SXin Li  Test14A *a;
346*67e74705SXin Li  Test14B *b;
347*67e74705SXin Li  id i;
348*67e74705SXin Li  id cla[10];
349*67e74705SXin Li  id vla[test14_cond() + 10];
350*67e74705SXin Li
351*67e74705SXin Li  test14_consume((__strong id*) &a);
352*67e74705SXin Li  test14_consume((test14_cond() ? (__strong id*) &b : &i));
353*67e74705SXin Li  test14_consume(test14_cond() ? 0 : &a);
354*67e74705SXin Li  test14_consume(test14_cond() ? (void*) 0 : (&a));
355*67e74705SXin Li  test14_consume(cla); // expected-error {{passing address of non-scalar object to __autoreleasing parameter for write-back}}
356*67e74705SXin Li  test14_consume(vla); // expected-error {{passing address of non-scalar object to __autoreleasing parameter for write-back}}
357*67e74705SXin Li  test14_consume(&cla[5]); // expected-error {{passing address of non-scalar object to __autoreleasing parameter for write-back}}
358*67e74705SXin Li
359*67e74705SXin Li  __strong id *test14_indirect(void);
360*67e74705SXin Li  test14_consume(test14_indirect()); // expected-error {{passing address of non-local object to __autoreleasing parameter for write-back}}
361*67e74705SXin Li
362*67e74705SXin Li  extern id test14_global;
363*67e74705SXin Li  test14_consume(&test14_global); // expected-error {{passing address of non-local object to __autoreleasing parameter for write-back}}
364*67e74705SXin Li
365*67e74705SXin Li  extern __strong id *test14_global_ptr;
366*67e74705SXin Li  test14_consume(test14_global_ptr); // expected-error {{passing address of non-local object to __autoreleasing parameter for write-back}}
367*67e74705SXin Li
368*67e74705SXin Li  static id static_local;
369*67e74705SXin Li  test14_consume(&static_local); // expected-error {{passing address of non-local object to __autoreleasing parameter for write-back}}
370*67e74705SXin Li
371*67e74705SXin Li  __weak id* wip;
372*67e74705SXin Li  test14_nowriteback(&static_local); // okay, not a write-back.
373*67e74705SXin Li  test14_nowriteback(wip); // expected-error{{passing '__weak id *' to parameter of type '__autoreleasing id const *' changes retain/release properties of pointer}}
374*67e74705SXin Li}
375*67e74705SXin Li
376*67e74705SXin Livoid test15() {
377*67e74705SXin Li  __block __autoreleasing id x; // expected-error {{__block variables cannot have __autoreleasing ownership}}
378*67e74705SXin Li}
379*67e74705SXin Li
380*67e74705SXin Listruct Test16;
381*67e74705SXin Li@interface Test16a
382*67e74705SXin Li- (void) test16_0: (int) x;
383*67e74705SXin Li- (int) test16_1: (int) x; // expected-note {{one possibility}}
384*67e74705SXin Li- (int) test16_2: (int) x; // expected-note {{one possibility}}
385*67e74705SXin Li- (id) test16_3: (int) x __attribute__((ns_returns_retained)); // expected-note {{one possibility}}
386*67e74705SXin Li- (void) test16_4: (int) x __attribute__((ns_consumes_self)); // expected-note {{one possibility}}
387*67e74705SXin Li- (void) test16_5: (id) __attribute__((ns_consumed)) x; // expected-note {{one possibility}}
388*67e74705SXin Li- (void) test16_6: (id) x;
389*67e74705SXin Li@end
390*67e74705SXin Li
391*67e74705SXin Li@interface Test16b
392*67e74705SXin Li- (void) test16_0: (int) x;
393*67e74705SXin Li- (int) test16_1: (char*) x; // expected-note {{also found}}
394*67e74705SXin Li- (char*) test16_2: (int) x; // expected-note {{also found}}
395*67e74705SXin Li- (id) test16_3: (int) x; // expected-note {{also found}}
396*67e74705SXin Li- (void) test16_4: (int) x; // expected-note {{also found}}
397*67e74705SXin Li- (void) test16_5: (id) x; // expected-note {{also found}}
398*67e74705SXin Li- (void) test16_6: (struct Test16 *) x;
399*67e74705SXin Li@end
400*67e74705SXin Li
401*67e74705SXin Livoid test16(void) {
402*67e74705SXin Li  id v;
403*67e74705SXin Li  [v test16_0: 0];
404*67e74705SXin Li  [v test16_1: 0]; // expected-error {{multiple methods named 'test16_1:' found with mismatched result, parameter type or attributes}}
405*67e74705SXin Li  [v test16_2: 0]; // expected-error {{multiple methods named}}
406*67e74705SXin Li  [v test16_3: 0]; // expected-error {{multiple methods named}}
407*67e74705SXin Li  [v test16_4: 0]; // expected-error {{multiple methods named}}
408*67e74705SXin Li  [v test16_5: 0]; // expected-error {{multiple methods named}}
409*67e74705SXin Li  [v test16_6: 0];
410*67e74705SXin Li}
411*67e74705SXin Li
412*67e74705SXin Li@class Test17; // expected-note 2{{forward declaration of class here}}
413*67e74705SXin Li@protocol Test17p
414*67e74705SXin Li- (void) test17;
415*67e74705SXin Li+ (void) test17;
416*67e74705SXin Li@end
417*67e74705SXin Livoid test17(void) {
418*67e74705SXin Li  Test17 *v0;
419*67e74705SXin Li  [v0 test17]; // expected-error {{receiver type 'Test17' for instance message is a forward declaration}}
420*67e74705SXin Li
421*67e74705SXin Li  Test17<Test17p> *v1;
422*67e74705SXin Li  [v1 test17]; // expected-error {{receiver type 'Test17<Test17p>' for instance message is a forward declaration}}
423*67e74705SXin Li
424*67e74705SXin Li  [Test17 test17]; // expected-error {{receiver 'Test17' for class message is a forward declaration}}
425*67e74705SXin Li}
426*67e74705SXin Li
427*67e74705SXin Livoid test18(void) {
428*67e74705SXin Li  id x;
429*67e74705SXin Li  [x test18]; // expected-error {{instance method 'test18' not found ; did you mean 'test17'?}}
430*67e74705SXin Li}
431*67e74705SXin Li
432*67e74705SXin Liextern struct Test19 *test19a;
433*67e74705SXin Listruct Test19 *const test19b = 0;
434*67e74705SXin Livoid test19(void) {
435*67e74705SXin Li  id x;
436*67e74705SXin Li  x = (id) test19a; // expected-error {{bridged cast}} \
437*67e74705SXin Li  // expected-note{{use __bridge to convert directly (no change in ownership)}} \
438*67e74705SXin Li  // expected-note{{use CFBridgingRelease call to transfer ownership of a +1 'struct Test19 *' into ARC}}
439*67e74705SXin Li  x = (id) test19b; // expected-error {{bridged cast}} \
440*67e74705SXin Li  // expected-note{{use __bridge to convert directly (no change in ownership)}} \
441*67e74705SXin Li  // expected-note{{use CFBridgingRelease call to transfer ownership of a +1 'struct Test19 *' into ARC}}
442*67e74705SXin Li}
443*67e74705SXin Li
444*67e74705SXin Li// rdar://problem/8951453
445*67e74705SXin Listatic __thread id test20_implicit; // expected-error {{thread-local variable has non-trivial ownership: type is '__strong id'}}
446*67e74705SXin Listatic __thread __strong id test20_strong; // expected-error {{thread-local variable has non-trivial ownership: type is '__strong id'}}
447*67e74705SXin Listatic __thread __weak id test20_weak; // expected-error {{thread-local variable has non-trivial ownership: type is '__weak id'}}
448*67e74705SXin Listatic __thread __autoreleasing id test20_autoreleasing; // expected-error {{thread-local variable has non-trivial ownership: type is '__autoreleasing id'}} expected-error {{global variables cannot have __autoreleasing ownership}}
449*67e74705SXin Listatic __thread __unsafe_unretained id test20_unsafe;
450*67e74705SXin Livoid test20(void) {
451*67e74705SXin Li  static __thread id test20_implicit; // expected-error {{thread-local variable has non-trivial ownership: type is '__strong id'}}
452*67e74705SXin Li  static __thread __strong id test20_strong; // expected-error {{thread-local variable has non-trivial ownership: type is '__strong id'}}
453*67e74705SXin Li  static __thread __weak id test20_weak; // expected-error {{thread-local variable has non-trivial ownership: type is '__weak id'}}
454*67e74705SXin Li  static __thread __autoreleasing id test20_autoreleasing; // expected-error {{thread-local variable has non-trivial ownership: type is '__autoreleasing id'}} expected-error {{global variables cannot have __autoreleasing ownership}}
455*67e74705SXin Li  static __thread __unsafe_unretained id test20_unsafe;
456*67e74705SXin Li}
457*67e74705SXin Li
458*67e74705SXin Li// rdar://9310049
459*67e74705SXin Li_Bool fn(id obj) {
460*67e74705SXin Li    return (_Bool)obj;
461*67e74705SXin Li}
462*67e74705SXin Li
463*67e74705SXin Li// Check casting w/ ownership qualifiers.
464*67e74705SXin Livoid test21() {
465*67e74705SXin Li  __strong id *sip;
466*67e74705SXin Li  (void)(__weak id *)sip; // expected-error{{casting '__strong id *' to type '__weak id *' changes retain/release properties of pointer}}
467*67e74705SXin Li  (void)(__weak const id *)sip; // expected-error{{casting '__strong id *' to type '__weak id const *' changes retain/release properties of pointer}}
468*67e74705SXin Li  (void)(__autoreleasing id *)sip; // expected-error{{casting '__strong id *' to type '__autoreleasing id *' changes retain/release properties of pointer}}
469*67e74705SXin Li  (void)(__autoreleasing const id *)sip; // okay
470*67e74705SXin Li}
471*67e74705SXin Li
472*67e74705SXin Li// rdar://problem/9340462
473*67e74705SXin Livoid test22(id x[]) { // expected-error {{must explicitly describe intended ownership of an object array parameter}}
474*67e74705SXin Li}
475*67e74705SXin Li
476*67e74705SXin Li// rdar://problem/9400219
477*67e74705SXin Livoid test23(void) {
478*67e74705SXin Li  void *ptr;
479*67e74705SXin Li  ptr = @"foo";
480*67e74705SXin Li  ptr = (ptr ? @"foo" : 0);
481*67e74705SXin Li  ptr = (ptr ? @"foo" : @"bar");
482*67e74705SXin Li}
483*67e74705SXin Li
484*67e74705SXin Liid test24(void) {
485*67e74705SXin Li  extern void test24_helper(void);
486*67e74705SXin Li  return test24_helper(), (void*) 0;
487*67e74705SXin Li}
488*67e74705SXin Li
489*67e74705SXin Li// rdar://9400841
490*67e74705SXin Li@interface Base
491*67e74705SXin Li@property (assign) id content;
492*67e74705SXin Li@end
493*67e74705SXin Li
494*67e74705SXin Li@interface Foo : Base
495*67e74705SXin Li-(void)test;
496*67e74705SXin Li@end
497*67e74705SXin Li
498*67e74705SXin Li@implementation Foo
499*67e74705SXin Li-(void)test {
500*67e74705SXin Li	super.content = 0;
501*67e74705SXin Li}
502*67e74705SXin Li@end
503*67e74705SXin Li
504*67e74705SXin Li// <rdar://problem/9398437>
505*67e74705SXin Livoid test25(Class *classes) {
506*67e74705SXin Li  Class *other_classes;
507*67e74705SXin Li  test25(other_classes);
508*67e74705SXin Li}
509*67e74705SXin Li
510*67e74705SXin Livoid test26(id y) {
511*67e74705SXin Li  extern id test26_var1;
512*67e74705SXin Li  __sync_swap(&test26_var1, 0, y); // expected-error {{cannot perform atomic operation on a pointer to type '__strong id': type has non-trivial ownership}}
513*67e74705SXin Li
514*67e74705SXin Li  extern __unsafe_unretained id test26_var2;
515*67e74705SXin Li  __sync_swap(&test26_var2, 0, y);
516*67e74705SXin Li}
517*67e74705SXin Li
518*67e74705SXin Li@interface Test26
519*67e74705SXin Li- (id) init;
520*67e74705SXin Li- (id) initWithInt: (int) x;
521*67e74705SXin Li@end
522*67e74705SXin Li@implementation Test26
523*67e74705SXin Li- (id) init { return self; }
524*67e74705SXin Li- (id) initWithInt: (int) x {
525*67e74705SXin Li  [self init]; // expected-error {{the result of a delegate init call must be immediately returned or assigned to 'self'}}
526*67e74705SXin Li  return self;
527*67e74705SXin Li}
528*67e74705SXin Li@end
529*67e74705SXin Li
530*67e74705SXin Li// rdar://9525555
531*67e74705SXin Li@interface  Test27 {
532*67e74705SXin Li  __weak id _myProp1;
533*67e74705SXin Li  id myProp2;
534*67e74705SXin Li}
535*67e74705SXin Li@property id x;
536*67e74705SXin Li@property (readonly) id ro;
537*67e74705SXin Li@property (readonly) id custom_ro;
538*67e74705SXin Li@property int y;
539*67e74705SXin Li
540*67e74705SXin Li@property (readonly) __weak id myProp1;
541*67e74705SXin Li@property (readonly) id myProp2;
542*67e74705SXin Li@property (readonly) __strong id myProp3;
543*67e74705SXin Li@end
544*67e74705SXin Li
545*67e74705SXin Li@implementation Test27
546*67e74705SXin Li@synthesize x;
547*67e74705SXin Li@synthesize ro;
548*67e74705SXin Li@synthesize y;
549*67e74705SXin Li
550*67e74705SXin Li@synthesize myProp1 = _myProp1;
551*67e74705SXin Li@synthesize myProp2;
552*67e74705SXin Li@synthesize myProp3;
553*67e74705SXin Li
554*67e74705SXin Li-(id)custom_ro { return 0; }
555*67e74705SXin Li@end
556*67e74705SXin Li
557*67e74705SXin Li// rdar://9569264
558*67e74705SXin Li@interface Test28
559*67e74705SXin Li@property (nonatomic, assign) __strong id a; // expected-error {{unsafe_unretained property 'a' may not also be declared __strong}}
560*67e74705SXin Li@end
561*67e74705SXin Li
562*67e74705SXin Li@interface Test28 ()
563*67e74705SXin Li@property (nonatomic, assign) __strong id b; // expected-error {{unsafe_unretained property 'b' may not also be declared __strong}}
564*67e74705SXin Li@end
565*67e74705SXin Li
566*67e74705SXin Li@implementation Test28
567*67e74705SXin Li@synthesize a;
568*67e74705SXin Li@synthesize b;
569*67e74705SXin Li@end
570*67e74705SXin Li
571*67e74705SXin Li// rdar://9573962
572*67e74705SXin Litypedef struct Bark Bark;
573*67e74705SXin Li@interface Test29
574*67e74705SXin Li@property Bark* P;
575*67e74705SXin Li@end
576*67e74705SXin Li
577*67e74705SXin Li@implementation Test29
578*67e74705SXin Li@synthesize P;
579*67e74705SXin Li- (id)Meth {
580*67e74705SXin Li  Bark** f = &P;
581*67e74705SXin Li  return 0;
582*67e74705SXin Li}
583*67e74705SXin Li@end
584*67e74705SXin Li
585*67e74705SXin Li// rdar://9495837
586*67e74705SXin Li@interface Test30
587*67e74705SXin Li+ (id) new;
588*67e74705SXin Li- (void)Meth;
589*67e74705SXin Li@end
590*67e74705SXin Li
591*67e74705SXin Li@implementation Test30
592*67e74705SXin Li+ (id) new { return 0; }
593*67e74705SXin Li- (void) Meth {
594*67e74705SXin Li  __weak id x = [Test30 new]; // expected-warning {{assigning retained object to weak variable}}
595*67e74705SXin Li  id __unsafe_unretained u = [Test30 new]; // expected-warning {{assigning retained object to unsafe_unretained variable}}
596*67e74705SXin Li  id y = [Test30 new];
597*67e74705SXin Li  x = [Test30 new]; // expected-warning {{assigning retained object to weak variable}}
598*67e74705SXin Li  u = [Test30 new]; // expected-warning {{assigning retained object to unsafe_unretained variable}}
599*67e74705SXin Li  y = [Test30 new];
600*67e74705SXin Li}
601*67e74705SXin Li@end
602*67e74705SXin Li
603*67e74705SXin Li// rdar://9411838
604*67e74705SXin Li@protocol PTest31 @end
605*67e74705SXin Li
606*67e74705SXin Liint Test31() {
607*67e74705SXin Li    Class cls;
608*67e74705SXin Li    id ids;
609*67e74705SXin Li    id<PTest31> pids;
610*67e74705SXin Li    Class<PTest31> pcls;
611*67e74705SXin Li
612*67e74705SXin Li    int i =  (ids->isa ? 1 : 0); // expected-error {{member reference base type 'id' is not a structure or union}}
613*67e74705SXin Li    int j = (pids->isa ? 1 : 0); // expected-error {{member reference base type 'id<PTest31>' is not a structure or union}}
614*67e74705SXin Li    int k = (pcls->isa ? i : j); // expected-error {{member reference base type 'Class<PTest31>' is not a structure or union}}
615*67e74705SXin Li    return cls->isa ? i : j; // expected-error {{member reference base type 'Class' is not a structure or union}}
616*67e74705SXin Li}
617*67e74705SXin Li
618*67e74705SXin Li// rdar://9612030
619*67e74705SXin Li@interface ITest32 {
620*67e74705SXin Li@public
621*67e74705SXin Li id ivar;
622*67e74705SXin Li}
623*67e74705SXin Li@end
624*67e74705SXin Li
625*67e74705SXin Liid Test32(__weak ITest32 *x) {
626*67e74705SXin Li  __weak ITest32 *y;
627*67e74705SXin Li  x->ivar = 0; // expected-error {{dereferencing a __weak pointer is not allowed}}
628*67e74705SXin Li  return y ? y->ivar     // expected-error {{dereferencing a __weak pointer is not allowed}}
629*67e74705SXin Li           : (*x).ivar;  // expected-error {{dereferencing a __weak pointer is not allowed}}
630*67e74705SXin Li}
631*67e74705SXin Li
632*67e74705SXin Li// rdar://9619861
633*67e74705SXin Liextern int printf(const char*, ...);
634*67e74705SXin Litypedef long intptr_t;
635*67e74705SXin Li
636*67e74705SXin Liint Test33(id someid) {
637*67e74705SXin Li  printf( "Hello%ld", (intptr_t)someid);
638*67e74705SXin Li  return (int)someid;
639*67e74705SXin Li}
640*67e74705SXin Li
641*67e74705SXin Li// rdar://9636091
642*67e74705SXin Li@interface I34
643*67e74705SXin Li@property (nonatomic, retain) id newName __attribute__((ns_returns_not_retained)) ;
644*67e74705SXin Li
645*67e74705SXin Li@property (nonatomic, retain) id newName1 __attribute__((ns_returns_not_retained)) ;
646*67e74705SXin Li- (id) newName1 __attribute__((ns_returns_not_retained));
647*67e74705SXin Li
648*67e74705SXin Li@property (nonatomic, retain) id newName2 __attribute__((ns_returns_not_retained)); // expected-note {{roperty declared here}}
649*67e74705SXin Li- (id) newName2;   // expected-warning {{property declared as returning non-retained objects; getter returning retained objects}}
650*67e74705SXin Li@end
651*67e74705SXin Li
652*67e74705SXin Li@implementation I34
653*67e74705SXin Li@synthesize newName;
654*67e74705SXin Li
655*67e74705SXin Li@synthesize newName1;
656*67e74705SXin Li- (id) newName1 { return 0; }
657*67e74705SXin Li
658*67e74705SXin Li@synthesize newName2;
659*67e74705SXin Li@end
660*67e74705SXin Li
661*67e74705SXin Livoid test35(void) {
662*67e74705SXin Li  extern void test36_helper(id*);
663*67e74705SXin Li  id x;
664*67e74705SXin Li  __strong id *xp = 0;
665*67e74705SXin Li
666*67e74705SXin Li  test36_helper(&x);
667*67e74705SXin Li  test36_helper(xp); // expected-error {{passing address of non-local object to __autoreleasing parameter for write-back}}
668*67e74705SXin Li
669*67e74705SXin Li  // rdar://problem/9665710
670*67e74705SXin Li  __block id y;
671*67e74705SXin Li  test36_helper(&y);
672*67e74705SXin Li  ^{ test36_helper(&y); }();
673*67e74705SXin Li
674*67e74705SXin Li  __strong int non_objc_type; // expected-warning {{'__strong' only applies to Objective-C object or block pointer types}}
675*67e74705SXin Li}
676*67e74705SXin Li
677*67e74705SXin Livoid test36(int first, ...) {
678*67e74705SXin Li  // <rdar://problem/9758798>
679*67e74705SXin Li  __builtin_va_list arglist;
680*67e74705SXin Li  __builtin_va_start(arglist, first);
681*67e74705SXin Li  id obj = __builtin_va_arg(arglist, id);
682*67e74705SXin Li  __builtin_va_end(arglist);
683*67e74705SXin Li}
684*67e74705SXin Li
685*67e74705SXin Li@class Test37; // expected-note{{forward declaration of class here}}
686*67e74705SXin Livoid test37(Test37 *c) {
687*67e74705SXin Li  for (id y in c) { // expected-error {{collection expression type 'Test37' is a forward declaration}}
688*67e74705SXin Li    (void) y;
689*67e74705SXin Li  }
690*67e74705SXin Li
691*67e74705SXin Li  (void)sizeof(id*); // no error.
692*67e74705SXin Li}
693*67e74705SXin Li
694*67e74705SXin Li// rdar://problem/9887979
695*67e74705SXin Li@interface Test38
696*67e74705SXin Li@property int value;
697*67e74705SXin Li@end
698*67e74705SXin Livoid test38() {
699*67e74705SXin Li  extern Test38 *test38_helper(void);
700*67e74705SXin Li  switch (test38_helper().value) {
701*67e74705SXin Li  case 0:
702*67e74705SXin Li  case 1:
703*67e74705SXin Li    ;
704*67e74705SXin Li  }
705*67e74705SXin Li}
706*67e74705SXin Li
707*67e74705SXin Li// rdar://10186536
708*67e74705SXin Li@class NSColor;
709*67e74705SXin Livoid _NSCalc(NSColor* color, NSColor* bezelColors[]) __attribute__((unavailable("not available in automatic reference counting mode")));
710*67e74705SXin Li
711*67e74705SXin Livoid _NSCalcBeze(NSColor* color, NSColor* bezelColors[]); // expected-error {{must explicitly describe intended ownership of an object array parameter}}
712*67e74705SXin Li
713*67e74705SXin Li// rdar://9970739
714*67e74705SXin Li@interface RestaurantTableViewCell
715*67e74705SXin Li- (void) restaurantLocation;
716*67e74705SXin Li@end
717*67e74705SXin Li
718*67e74705SXin Li@interface Radar9970739
719*67e74705SXin Li- (void) Meth;
720*67e74705SXin Li@end
721*67e74705SXin Li
722*67e74705SXin Li@implementation Radar9970739
723*67e74705SXin Li- (void) Meth {
724*67e74705SXin Li  RestaurantTableViewCell *cell;
725*67e74705SXin Li  [cell restaurantLocatoin]; // expected-error {{no visible @interface for 'RestaurantTableViewCell' declares the selector 'restaurantLocatoin'}}
726*67e74705SXin Li}
727*67e74705SXin Li@end
728*67e74705SXin Li
729*67e74705SXin Li// rdar://11814185
730*67e74705SXin Li@interface Radar11814185
731*67e74705SXin Li@property (nonatomic, weak)  Radar11814185* picker1;
732*67e74705SXin Li+ alloc;
733*67e74705SXin Li- init;
734*67e74705SXin Li@end
735*67e74705SXin Li
736*67e74705SXin Li@implementation Radar11814185
737*67e74705SXin Li
738*67e74705SXin Li@synthesize picker1;
739*67e74705SXin Li
740*67e74705SXin Li- (void)viewDidLoad
741*67e74705SXin Li{
742*67e74705SXin Li    picker1 = [[Radar11814185 alloc] init]; // expected-warning {{assigning retained object to weak variable; object will be released after assignment}}
743*67e74705SXin Li    self.picker1 = [[Radar11814185 alloc] init]; // expected-warning {{assigning retained object to weak property; object will be released after assignment}}
744*67e74705SXin Li}
745*67e74705SXin Li
746*67e74705SXin Li+ alloc { return 0; }
747*67e74705SXin Li- init { return 0; }
748*67e74705SXin Li@end
749*67e74705SXin Li
750*67e74705SXin Li// <rdar://problem/12569201>.  Warn on cases of initializing a weak variable
751*67e74705SXin Li// with an Objective-C object literal.
752*67e74705SXin Livoid rdar12569201(id key, id value) {
753*67e74705SXin Li    // Declarations.
754*67e74705SXin Li    __weak id x = @"foo"; // no-warning
755*67e74705SXin Li    __weak id y = @{ key : value }; // expected-warning {{assigning dictionary literal to a weak variable; object will be released after assignment}}
756*67e74705SXin Li    __weak id z = @[ value ]; // expected-warning {{assigning array literal to a weak variable; object will be released after assignment}}
757*67e74705SXin Li    __weak id b = ^() {}; // expected-warning {{assigning block literal to a weak variable; object will be released after assignment}}
758*67e74705SXin Li    __weak id n = @42; // expected-warning {{assigning numeric literal to a weak variable; object will be released after assignment}}
759*67e74705SXin Li    __weak id e = @(42); // expected-warning {{assigning numeric literal to a weak variable; object will be released after assignment}}
760*67e74705SXin Li    __weak id m = @(41 + 1); // expected-warning {{assigning boxed expression to a weak variable; object will be released after assignment}}
761*67e74705SXin Li
762*67e74705SXin Li    // Assignments.
763*67e74705SXin Li    y = @{ key : value }; // expected-warning {{assigning dictionary literal to a weak variable; object will be released after assignment}}
764*67e74705SXin Li    z = @[ value ]; // expected-warning {{assigning array literal to a weak variable; object will be released after assignment}}
765*67e74705SXin Li    b = ^() {}; // expected-warning {{assigning block literal to a weak variable; object will be released after assignment}}
766*67e74705SXin Li    n = @42; // expected-warning {{assigning numeric literal to a weak variable; object will be released after assignment}}
767*67e74705SXin Li    e = @(42); // expected-warning {{assigning numeric literal to a weak variable; object will be released after assignment}}
768*67e74705SXin Li    m = @(41 + 1); // expected-warning {{assigning boxed expression to a weak variable; object will be released after assignment}}
769*67e74705SXin Li}
770*67e74705SXin Li
771*67e74705SXin Li@interface C
772*67e74705SXin Li- (void)method:(id[])objects; // expected-error{{must explicitly describe intended ownership of an object array parameter}}
773*67e74705SXin Li@end
774*67e74705SXin Li
775*67e74705SXin Li// rdar://13752880
776*67e74705SXin Li@interface NSMutableArray : NSArray @end
777*67e74705SXin Li
778*67e74705SXin Litypedef __strong NSMutableArray * PSNS;
779*67e74705SXin Li
780*67e74705SXin Livoid test(NSArray *x) {
781*67e74705SXin Li  NSMutableArray *y = x; // expected-warning {{incompatible pointer types initializing 'NSMutableArray *' with an expression of type 'NSArray *'}}
782*67e74705SXin Li  __strong NSMutableArray *y1 = x; // expected-warning {{incompatible pointer types initializing 'NSMutableArray *' with an expression of type 'NSArray *'}}
783*67e74705SXin Li  PSNS y2 = x; // expected-warning {{incompatible pointer types initializing 'NSMutableArray *' with an expression of type 'NSArray *'}}
784*67e74705SXin Li}
785*67e74705SXin Li
786*67e74705SXin Li// rdar://15123684
787*67e74705SXin Li@class NSString;
788*67e74705SXin Li
789*67e74705SXin Livoid foo(NSArray *array) {
790*67e74705SXin Li  for (NSString *string in array) {
791*67e74705SXin Li    for (string in @[@"blah", @"more blah", string]) { // expected-error {{selector element of type 'NSString *const __strong' cannot be a constant l-value}}
792*67e74705SXin Li    }
793*67e74705SXin Li  }
794*67e74705SXin Li}
795*67e74705SXin Li
796*67e74705SXin Li// rdar://16627903
797*67e74705SXin Liextern void abort();
798*67e74705SXin Li#define TKAssertEqual(a, b) do{\
799*67e74705SXin Li    __typeof(a) a_res = (a);\
800*67e74705SXin Li    __typeof(b) b_res = (b);\
801*67e74705SXin Li    if ((a_res) != (b_res)) {\
802*67e74705SXin Li        abort();\
803*67e74705SXin Li    }\
804*67e74705SXin Li}while(0)
805*67e74705SXin Li
806*67e74705SXin Liint garf() {
807*67e74705SXin Li  id object;
808*67e74705SXin Li  TKAssertEqual(object, nil);
809*67e74705SXin Li  TKAssertEqual(object, (id)nil);
810*67e74705SXin Li}
811