blob: b3405c05e2627bfa5807b0fbfe9c1288571dca22 [file] [log] [blame]
John McCalld1e40d52011-10-02 01:16:38 +00001// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fobjc-runtime-has-weak -fsyntax-only -fobjc-arc -fblocks -verify %s
John McCallf85e1932011-06-15 23:02:42 +00002
3typedef unsigned long NSUInteger;
4
5void test0(void (*fn)(int), int val) {
6 fn(val);
7}
8
9@interface A
10- (id)retain;
11- (id)autorelease;
12- (oneway void)release;
13- (void)dealloc;
14- (NSUInteger)retainCount;
15@end
16
17void test1(A *a) {
18 SEL s = @selector(retain); // expected-error {{ARC forbids use of 'retain' in a @selector}}
19 s = @selector(release); // expected-error {{ARC forbids use of 'release' in a @selector}}
20 s = @selector(autorelease); // expected-error {{ARC forbids use of 'autorelease' in a @selector}}
21 s = @selector(dealloc); // expected-error {{ARC forbids use of 'dealloc' in a @selector}}
22 [a dealloc]; // expected-error {{ARC forbids explicit message send of 'dealloc'}}
23 [a retain]; // expected-error {{ARC forbids explicit message send of 'retain'}}
24 [a retainCount]; // expected-error {{ARC forbids explicit message send of 'retainCount'}}
25 [a release]; // expected-error {{ARC forbids explicit message send of 'release'}}
26 [a autorelease]; // expected-error {{ARC forbids explicit message send of 'autorelease'}}
27}
28
29@interface Test2 : A
30- (void) dealloc;
31@end
32@implementation Test2
33- (void) dealloc {
34 // This should maybe just be ignored. We're just going to warn about it for now.
35 [super dealloc]; // expected-error {{ARC forbids explicit message send of 'dealloc'}}
36}
37@end
38
39__weak __strong id x; // expected-error {{the type '__strong id' already has retainment attributes}}
40
41// rdar://8843638
42
43@interface I
Fariborz Jahanianfefe91e2011-07-28 23:19:50 +000044- (id)retain; // expected-note {{method declared here}}
45- (id)autorelease; // expected-note {{method declared here}}
46- (oneway void)release; // expected-note {{method declared here}}
47- (NSUInteger)retainCount; // expected-note {{method declared here}}
John McCallf85e1932011-06-15 23:02:42 +000048@end
49
50@implementation I
51- (id)retain{return 0;} // expected-error {{ARC forbids implementation of 'retain'}}
52- (id)autorelease{return 0;} // expected-error {{ARC forbids implementation of 'autorelease'}}
53- (oneway void)release{} // expected-error {{ARC forbids implementation of 'release'}}
54- (NSUInteger)retainCount{ return 0; } // expected-error {{ARC forbids implementation of 'retainCount'}}
55@end
56
57@implementation I(CAT)
Fariborz Jahanianfefe91e2011-07-28 23:19:50 +000058- (id)retain{return 0;} // expected-error {{ARC forbids implementation of 'retain'}} \
59 // expected-warning {{category is implementing a method which will also be implemented by its primary class}}
60- (id)autorelease{return 0;} // expected-error {{ARC forbids implementation of 'autorelease'}} \
61 // expected-warning {{category is implementing a method which will also be implemented by its primary class}}
62- (oneway void)release{} // expected-error {{ARC forbids implementation of 'release'}} \
63 // expected-warning {{category is implementing a method which will also be implemented by its primary class}}
64- (NSUInteger)retainCount{ return 0; } // expected-error {{ARC forbids implementation of 'retainCount'}} \
65 // expected-warning {{category is implementing a method which will also be implemented by its primary class}}
John McCallf85e1932011-06-15 23:02:42 +000066@end
67
68// rdar://8861761
69
70@interface B
71-(id)alloc;
72- (id)initWithInt: (int) i;
73@end
74
75void rdar8861761() {
76 B *o1 = [[B alloc] initWithInt:0];
77 B *o2 = [B alloc];
78 [o2 initWithInt:0]; // expected-warning {{expression result unused}}
79}
80
81// rdar://8925835
82@interface rdar8925835
83- (void)foo:(void (^)(unsigned captureCount, I * const capturedStrings[captureCount]))block;
84@end
85
86void test5() {
87 extern void test5_helper(__autoreleasing id *);
88 id x;
89
90 // Okay because of magic temporaries.
91 test5_helper(&x);
92
93 __autoreleasing id *a = &x; // expected-error {{initializing '__autoreleasing id *' with an expression of type '__strong id *' changes retain/release properties of pointer}}
94
95 a = &x; // expected-error {{assigning '__strong id *' to '__autoreleasing id *' changes retain/release properties of pointer}}
96
97 extern void test5_helper2(id const *);
98 test5_helper2(&x);
99
100 extern void test5_helper3(__weak id *); // expected-note {{passing argument to parameter here}}
101 test5_helper3(&x); // expected-error {{passing '__strong id *' to parameter of type '__weak id *' changes retain/release properties of pointer}}
102}
103
104// rdar://problem/8937869
105void test6(unsigned cond) {
106 switch (cond) {
107 case 0:
108 ;
109 id x; // expected-note {{jump bypasses initialization of retaining variable}}
110
111 case 1: // expected-error {{switch case is in protected scope}}
112 break;
113 }
114}
115
116@class NSError;
117void test7(void) {
118 extern void test7_helper(NSError **);
119 NSError *err;
120 test7_helper(&err);
121}
122void test7_weak(void) {
123 extern void test7_helper(NSError **);
124 __weak NSError *err;
125 test7_helper(&err);
126}
127void test7_unsafe(void) {
128 extern void test7_helper(NSError **); // expected-note {{passing argument to parameter here}}
129 __unsafe_unretained NSError *err;
130 test7_helper(&err); // expected-error {{passing 'NSError *__unsafe_unretained *' to parameter of type 'NSError *__autoreleasing *' changes retain/release properties of pointer}}
131}
132
133@class Test8_incomplete;
134@interface Test8_complete @end;
135@interface Test8_super @end;
136@interface Test8 : Test8_super
137- (id) init00;
138- (id) init01; // expected-note {{declaration in interface}} \
139 // expected-note{{overridden method}}
140- (id) init02; // expected-note{{overridden method}}
141- (id) init03; // covariance
142- (id) init04; // covariance
143- (id) init05; // expected-note{{overridden method}}
144
145- (void) init10; // expected-note {{declaration in interface is not in the 'init' family because its result type is not an object pointer}}
146- (void) init11;
147- (void) init12;
148- (void) init13; // expected-note {{declaration in interface is not in the 'init' family because its result type is not an object pointer}}
149- (void) init14; // expected-note {{declaration in interface is not in the 'init' family because its result type is not an object pointer}}
150- (void) init15;
151
152// These should be invalid to actually call.
153- (Test8_incomplete*) init20;
154- (Test8_incomplete*) init21; // expected-note {{declaration in interface}}
155- (Test8_incomplete*) init22;
156- (Test8_incomplete*) init23;
157- (Test8_incomplete*) init24;
158- (Test8_incomplete*) init25;
159
160- (Test8_super*) init30; // id exception to covariance
161- (Test8_super*) init31; // expected-note {{declaration in interface}} \
162 // expected-note{{overridden method}}
163- (Test8_super*) init32; // expected-note{{overridden method}}
164- (Test8_super*) init33;
165- (Test8_super*) init34; // covariance
166- (Test8_super*) init35; // expected-note{{overridden method}}
167
168- (Test8*) init40; // id exception to covariance
169- (Test8*) init41; // expected-note {{declaration in interface}} \
170 // expected-note{{overridden method}}
171- (Test8*) init42; // expected-note{{overridden method}}
172- (Test8*) init43; // this should be a warning, but that's a general language thing, not an ARC thing
173- (Test8*) init44;
174- (Test8*) init45; // expected-note{{overridden method}}
175
176- (Test8_complete*) init50; // expected-error {{init methods must return a type related to the receiver type}}
177- (Test8_complete*) init51; // expected-error {{init methods must return a type related to the receiver type}}
178- (Test8_complete*) init52; // expected-error {{init methods must return a type related to the receiver type}}
179- (Test8_complete*) init53; // expected-error {{init methods must return a type related to the receiver type}}
180- (Test8_complete*) init54; // expected-error {{init methods must return a type related to the receiver type}}
181- (Test8_complete*) init55; // expected-error {{init methods must return a type related to the receiver type}}
182@end
183@implementation Test8
184- (id) init00 { return 0; }
185- (id) init10 { return 0; } // expected-error {{method implementation does not match its declaration}}
186- (id) init20 { return 0; }
187- (id) init30 { return 0; }
188- (id) init40 { return 0; }
189- (id) init50 { return 0; }
190
191- (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}} \
192 // expected-warning{{ method is expected to return an instance of its class type 'Test8', but is declared to return 'void'}}
193- (void) init11 {}
194- (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}}
195- (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}} \
196 // expected-warning{{ method is expected to return an instance of its class type 'Test8', but is declared to return 'void'}}
197- (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}} \
198 // expected-warning{{ method is expected to return an instance of its class type 'Test8', but is declared to return 'void'}}
199- (void) init51 {}
200
201- (Test8_incomplete*) init02 { return 0; } // expected-error {{init methods must return a type related to the receiver type}} \
202 // expected-warning{{method is expected to return an instance of its class type 'Test8', but is declared to return 'Test8_incomplete *'}}
203- (Test8_incomplete*) init12 { return 0; } // expected-error {{init methods must return a type related to the receiver type}}
204- (Test8_incomplete*) init22 { return 0; } // expected-error {{init methods must return a type related to the receiver type}}
205- (Test8_incomplete*) init32 { return 0; } // expected-error {{init methods must return a type related to the receiver type}} \
206 // expected-warning{{method is expected to return an instance of its class type 'Test8', but is declared to return 'Test8_incomplete *'}}
207- (Test8_incomplete*) init42 { return 0; } // expected-error {{init methods must return a type related to the receiver type}} \
208 // expected-warning{{method is expected to return an instance of its class type 'Test8', but is declared to return 'Test8_incomplete *'}}
209- (Test8_incomplete*) init52 { return 0; } // expected-error {{init methods must return a type related to the receiver type}}
210
211- (Test8_super*) init03 { return 0; }
212- (Test8_super*) init13 { return 0; } // expected-error {{method implementation does not match its declaration}}
213- (Test8_super*) init23 { return 0; }
214- (Test8_super*) init33 { return 0; }
215- (Test8_super*) init43 { return 0; }
216- (Test8_super*) init53 { return 0; }
217
218- (Test8*) init04 { return 0; }
219- (Test8*) init14 { return 0; } // expected-error {{method implementation does not match its declaration}}
220- (Test8*) init24 { return 0; }
221- (Test8*) init34 { return 0; }
222- (Test8*) init44 { return 0; }
223- (Test8*) init54 { return 0; }
224
225- (Test8_complete*) init05 { return 0; } // expected-error {{init methods must return a type related to the receiver type}} \
226 // expected-warning{{method is expected to return an instance of its class type 'Test8', but is declared to return 'Test8_complete *'}}
227- (Test8_complete*) init15 { return 0; } // expected-error {{init methods must return a type related to the receiver type}}
228- (Test8_complete*) init25 { return 0; } // expected-error {{init methods must return a type related to the receiver type}}
229- (Test8_complete*) init35 { return 0; } // expected-error {{init methods must return a type related to the receiver type}} \
230 // expected-warning{{method is expected to return an instance of its class type 'Test8', but is declared to return 'Test8_complete *'}}
231- (Test8_complete*) init45 { return 0; } // expected-error {{init methods must return a type related to the receiver type}} \
232 // expected-warning{{method is expected to return an instance of its class type 'Test8', but is declared to return 'Test8_complete *'}}
233- (Test8_complete*) init55 { return 0; } // expected-error {{init methods must return a type related to the receiver type}}
234@end
235
236@class Test9_incomplete;
237@interface Test9
238- (Test9_incomplete*) init1; // expected-error {{init methods must return a type related to the receiver type}}
239- (Test9_incomplete*) init2;
240@end
241id test9(Test9 *v) {
242 return [v init1];
243}
244
245// Test that the inference rules are different for fast enumeration variables.
246void test10(id collection) {
247 for (id x in collection) {
John McCall7acddac2011-06-17 06:42:21 +0000248 __strong id *ptr = &x; // expected-warning {{initializing '__strong id *' with an expression of type 'const __strong id *' discards qualifiers}}
John McCallf85e1932011-06-15 23:02:42 +0000249 }
250
251 for (__strong id x in collection) {
252 __weak id *ptr = &x; // expected-error {{initializing '__weak id *' with an expression of type '__strong id *' changes retain/release properties of pointer}}
253 }
254}
255
256// rdar://problem/9078626
257#define nil ((void*) 0)
258void test11(id op, void *vp) {
259 _Bool b;
260 b = (op == nil);
261 b = (nil == op);
262
263 b = (vp == nil);
264 b = (nil == vp);
265
John McCall5acb0c92011-10-17 18:40:02 +0000266 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 __bridge_retained}}
267 b = (op == vp); // expected-error {{implicit conversion of C pointer type 'void *' to Objective-C pointer type 'id' requires a bridged cast}} expected-note {{use __bridge}} expected-note {{use __bridge_transfer}}
John McCallf85e1932011-06-15 23:02:42 +0000268}
269
270void test12(id collection) {
271 for (id x in collection) {
272 x = 0; // expected-error {{fast enumeration variables can't be modified in ARC by default; declare the variable __strong to allow this}}
273 }
274
275 for (const id x in collection) {
276 x = 0; // expected-error {{read-only variable is not assignable}}
277 }
278
279 for (__strong id x in collection) {
280 x = 0;
281 }
282}
283
284@interface Test13
285- (id) init0;
286- (void) noninit;
287@end
288@implementation Test13
289- (id) init0 {
290 self = 0;
291}
292- (void) noninit {
293 self = 0; // expected-error {{cannot assign to 'self' outside of a method in the init family}}
294}
295@end
296
Ted Kremenek3045ce72011-10-25 04:52:20 +0000297// <rdar://problem/10274056>
298@interface Test13_B
299- (id) consumesSelf __attribute__((ns_consumes_self));
300@end
301@implementation Test13_B
302- (id) consumesSelf {
303 self = 0; // no-warning
304}
305@end
306
John McCallf85e1932011-06-15 23:02:42 +0000307// rdar://problem/9172151
308@class Test14A, Test14B;
309void test14() {
310 extern void test14_consume(id *);
311 extern int test14_cond(void);
312 extern float test14_nowriteback(id __autoreleasing const *); // expected-note{{passing argument to parameter here}}
313
314 Test14A *a;
315 Test14B *b;
316 id i;
317 id cla[10];
318 id vla[test14_cond() + 10];
319
320 test14_consume((__strong id*) &a);
321 test14_consume((test14_cond() ? (__strong id*) &b : &i));
322 test14_consume(test14_cond() ? 0 : &a);
323 test14_consume(test14_cond() ? (void*) 0 : (&a));
324 test14_consume(cla); // expected-error {{passing address of non-scalar object to __autoreleasing parameter for write-back}}
325 test14_consume(vla); // expected-error {{passing address of non-scalar object to __autoreleasing parameter for write-back}}
326 test14_consume(&cla[5]); // expected-error {{passing address of non-scalar object to __autoreleasing parameter for write-back}}
327
328 __strong id *test14_indirect(void);
329 test14_consume(test14_indirect()); // expected-error {{passing address of non-local object to __autoreleasing parameter for write-back}}
330
331 extern id test14_global;
332 test14_consume(&test14_global); // expected-error {{passing address of non-local object to __autoreleasing parameter for write-back}}
333
334 extern __strong id *test14_global_ptr;
335 test14_consume(test14_global_ptr); // expected-error {{passing address of non-local object to __autoreleasing parameter for write-back}}
336
337 static id static_local;
338 test14_consume(&static_local); // expected-error {{passing address of non-local object to __autoreleasing parameter for write-back}}
339
340 __weak id* wip;
341 test14_nowriteback(&static_local); // okay, not a write-back.
342 test14_nowriteback(wip); // expected-error{{passing '__weak id *' to parameter of type '__autoreleasing id const *' changes retain/release properties of pointer}}
343}
344
345void test15() {
Argyrios Kyrtzidisb8b03132011-06-24 00:08:59 +0000346 __block __autoreleasing id x; // expected-error {{__block variables cannot have __autoreleasing ownership}}
John McCallf85e1932011-06-15 23:02:42 +0000347}
348
349struct Test16;
350@interface Test16a
351- (void) test16_0: (int) x;
352- (int) test16_1: (int) x; // expected-note {{one possibility}}
353- (int) test16_2: (int) x; // expected-note {{one possibility}}
354- (id) test16_3: (int) x __attribute__((ns_returns_retained)); // expected-note {{one possibility}}
355- (void) test16_4: (int) x __attribute__((ns_consumes_self)); // expected-note {{one possibility}}
356- (void) test16_5: (id) __attribute__((ns_consumed)) x; // expected-note {{one possibility}}
357- (void) test16_6: (id) x;
358@end
359
360@interface Test16b
361- (void) test16_0: (int) x;
362- (int) test16_1: (char*) x; // expected-note {{also found}}
363- (char*) test16_2: (int) x; // expected-note {{also found}}
364- (id) test16_3: (int) x; // expected-note {{also found}}
365- (void) test16_4: (int) x; // expected-note {{also found}}
366- (void) test16_5: (id) x; // expected-note {{also found}}
367- (void) test16_6: (struct Test16 *) x;
368@end
369
370void test16(void) {
371 id v;
372 [v test16_0: 0];
373 [v test16_1: 0]; // expected-error {{multiple methods named 'test16_1:' found with mismatched result, parameter type or attributes}}
374 [v test16_2: 0]; // expected-error {{multiple methods named}}
375 [v test16_3: 0]; // expected-error {{multiple methods named}}
376 [v test16_4: 0]; // expected-error {{multiple methods named}}
377 [v test16_5: 0]; // expected-error {{multiple methods named}}
378 [v test16_6: 0];
379}
380
Douglas Gregorb3029962011-11-14 22:10:01 +0000381@class Test17; // expected-note 2{{forward declaration of class here}}
John McCallf85e1932011-06-15 23:02:42 +0000382@protocol Test17p
383- (void) test17;
384+ (void) test17;
385@end
386void test17(void) {
387 Test17 *v0;
388 [v0 test17]; // expected-error {{receiver type 'Test17' for instance message is a forward declaration}}
389
390 Test17<Test17p> *v1;
391 [v1 test17]; // expected-error {{receiver type 'Test17<Test17p>' for instance message is a forward declaration}}
392
393 [Test17 test17]; // expected-error {{receiver 'Test17' for class message is a forward declaration}}
394}
395
396void test18(void) {
397 id x;
398 [x test18]; // expected-error {{no known instance method for selector 'test18'}}
399}
400
401extern struct Test19 *test19a;
402struct Test19 *const test19b = 0;
403void test19(void) {
404 id x;
405 x = (id) test19a; // expected-error {{bridged cast}} \
406 // expected-note{{use __bridge to convert directly (no change in ownership))}} \
407 // expected-note{{use __bridge_transfer to transfer ownership of a +1 'struct Test19 *' into ARC}}
408 x = (id) test19b; // expected-error {{bridged cast}} \
409 // expected-note{{use __bridge to convert directly (no change in ownership)}} \
410 // expected-note{{use __bridge_transfer to transfer ownership of a +1 'struct Test19 *' into ARC}}
411}
412
413// rdar://problem/8951453
Argyrios Kyrtzidisb8b03132011-06-24 00:08:59 +0000414static __thread id test20_implicit; // expected-error {{thread-local variable has non-trivial ownership: type is '__strong id'}}
415static __thread __strong id test20_strong; // expected-error {{thread-local variable has non-trivial ownership: type is '__strong id'}}
416static __thread __weak id test20_weak; // expected-error {{thread-local variable has non-trivial ownership: type is '__weak id'}}
417static __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}}
John McCallf85e1932011-06-15 23:02:42 +0000418static __thread __unsafe_unretained id test20_unsafe;
419void test20(void) {
Argyrios Kyrtzidisb8b03132011-06-24 00:08:59 +0000420 static __thread id test20_implicit; // expected-error {{thread-local variable has non-trivial ownership: type is '__strong id'}}
421 static __thread __strong id test20_strong; // expected-error {{thread-local variable has non-trivial ownership: type is '__strong id'}}
422 static __thread __weak id test20_weak; // expected-error {{thread-local variable has non-trivial ownership: type is '__weak id'}}
423 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}}
John McCallf85e1932011-06-15 23:02:42 +0000424 static __thread __unsafe_unretained id test20_unsafe;
425}
426
427// rdar://9310049
428_Bool fn(id obj) {
429 return (_Bool)obj;
430}
431
Argyrios Kyrtzidisb8b03132011-06-24 00:08:59 +0000432// Check casting w/ ownership qualifiers.
John McCallf85e1932011-06-15 23:02:42 +0000433void test21() {
434 __strong id *sip;
435 (void)(__weak id *)sip; // expected-error{{casting '__strong id *' to type '__weak id *' changes retain/release properties of pointer}}
436 (void)(__weak const id *)sip; // expected-error{{casting '__strong id *' to type '__weak id const *' changes retain/release properties of pointer}}
437 (void)(__autoreleasing id *)sip; // expected-error{{casting '__strong id *' to type '__autoreleasing id *' changes retain/release properties of pointer}}
438 (void)(__autoreleasing const id *)sip; // okay
439}
440
441// rdar://problem/9340462
Argyrios Kyrtzidisb8b03132011-06-24 00:08:59 +0000442void test22(id x[]) { // expected-error {{must explicitly describe intended ownership of an object array parameter}}
John McCallf85e1932011-06-15 23:02:42 +0000443}
444
445// rdar://problem/9400219
446void test23(void) {
447 void *ptr;
448 ptr = @"foo";
449 ptr = (ptr ? @"foo" : 0);
450 ptr = (ptr ? @"foo" : @"bar");
451}
452
453id test24(void) {
454 extern void test24_helper(void);
455 return test24_helper(), (void*) 0;
456}
457
458// rdar://9400841
459@interface Base
460@property (assign) id content;
461@end
462
463@interface Foo : Base
464-(void)test;
465@end
466
467@implementation Foo
468-(void)test {
469 super.content = 0;
470}
471@end
472
473// <rdar://problem/9398437>
474void test25(Class *classes) {
475 Class *other_classes;
476 test25(other_classes);
477}
478
479void test26(id y) {
480 extern id test26_var1;
Argyrios Kyrtzidisb8b03132011-06-24 00:08:59 +0000481 __sync_swap(&test26_var1, 0, y); // expected-error {{cannot perform atomic operation on a pointer to type '__strong id': type has non-trivial ownership}}
John McCallf85e1932011-06-15 23:02:42 +0000482
483 extern __unsafe_unretained id test26_var2;
484 __sync_swap(&test26_var2, 0, y);
485}
486
487@interface Test26
488- (id) init;
489- (id) initWithInt: (int) x;
490@end
491@implementation Test26
492- (id) init { return self; }
493- (id) initWithInt: (int) x {
494 [self init]; // expected-error {{the result of a delegate init call must be immediately returned or assigned to 'self'}}
495 return self;
496}
497@end
498
499// rdar://9525555
Argyrios Kyrtzidis473506b2011-07-26 21:48:26 +0000500@interface Test27 {
501 __weak id _myProp1;
502 id myProp2;
503}
Fariborz Jahanianbc03aea2011-08-19 19:28:44 +0000504@property id x;
Fariborz Jahanianf21a92d2011-11-08 20:58:53 +0000505@property (readonly) id ro;
Argyrios Kyrtzidis0a68dc72011-07-12 04:30:16 +0000506@property (readonly) id custom_ro;
John McCallf85e1932011-06-15 23:02:42 +0000507@property int y;
Argyrios Kyrtzidis473506b2011-07-26 21:48:26 +0000508
Fariborz Jahanianf21a92d2011-11-08 20:58:53 +0000509@property (readonly) __weak id myProp1;
Argyrios Kyrtzidis473506b2011-07-26 21:48:26 +0000510@property (readonly) id myProp2;
511@property (readonly) __strong id myProp3;
John McCallf85e1932011-06-15 23:02:42 +0000512@end
513
Argyrios Kyrtzidis0a68dc72011-07-12 04:30:16 +0000514@implementation Test27
Fariborz Jahanianbc03aea2011-08-19 19:28:44 +0000515@synthesize x;
Fariborz Jahanianf21a92d2011-11-08 20:58:53 +0000516@synthesize ro;
Argyrios Kyrtzidis0a68dc72011-07-12 04:30:16 +0000517@synthesize y;
Argyrios Kyrtzidis473506b2011-07-26 21:48:26 +0000518
519@synthesize myProp1 = _myProp1;
520@synthesize myProp2;
521@synthesize myProp3;
522
Argyrios Kyrtzidis0a68dc72011-07-12 04:30:16 +0000523-(id)custom_ro { return 0; }
524@end
525
John McCallf85e1932011-06-15 23:02:42 +0000526// rdar://9569264
527@interface Test28
528@property (nonatomic, assign) __strong id a; // expected-error {{unsafe_unretained property 'a' may not also be declared __strong}}
529@end
530
531@interface Test28 ()
532@property (nonatomic, assign) __strong id b; // expected-error {{unsafe_unretained property 'b' may not also be declared __strong}}
533@end
534
535@implementation Test28
536@synthesize a;
537@synthesize b;
538@end
539
540// rdar://9573962
541typedef struct Bark Bark;
542@interface Test29
543@property Bark* P;
544@end
545
546@implementation Test29
547@synthesize P;
548- (id)Meth {
549 Bark** f = &P;
550 return 0;
551}
552@end
553
554// rdar://9495837
555@interface Test30
Fariborz Jahanian921c1432011-06-24 18:25:34 +0000556+ (id) new;
John McCallf85e1932011-06-15 23:02:42 +0000557- (void)Meth;
558@end
559
560@implementation Test30
Fariborz Jahanian921c1432011-06-24 18:25:34 +0000561+ (id) new { return 0; }
John McCallf85e1932011-06-15 23:02:42 +0000562- (void) Meth {
Argyrios Kyrtzidisd26fef02011-06-22 18:03:53 +0000563 __weak id x = [Test30 new]; // expected-warning {{assigning retained object to weak variable}}
564 id __unsafe_unretained u = [Test30 new]; // expected-warning {{assigning retained object to unsafe_unretained variable}}
John McCallf85e1932011-06-15 23:02:42 +0000565 id y = [Test30 new];
Argyrios Kyrtzidisd26fef02011-06-22 18:03:53 +0000566 x = [Test30 new]; // expected-warning {{assigning retained object to weak variable}}
567 u = [Test30 new]; // expected-warning {{assigning retained object to unsafe_unretained variable}}
John McCallf85e1932011-06-15 23:02:42 +0000568 y = [Test30 new];
569}
570@end
571
572// rdar://9411838
573@protocol PTest31 @end
574
575int Test31() {
576 Class cls;
577 id ids;
578 id<PTest31> pids;
579 Class<PTest31> pcls;
580
581 int i = (ids->isa ? 1 : 0); // expected-error {{member reference base type 'id' is not a structure or union}}
582 int j = (pids->isa ? 1 : 0); // expected-error {{member reference base type 'id<PTest31>' is not a structure or union}}
583 int k = (pcls->isa ? i : j); // expected-error {{member reference base type 'Class<PTest31>' is not a structure or union}}
584 return cls->isa ? i : j; // expected-error {{member reference base type 'Class' is not a structure or union}}
585}
Fariborz Jahanianb1f7d242011-06-16 17:29:56 +0000586
587// rdar://9612030
588@interface ITest32 {
589@public
590 id ivar;
591}
592@end
593
594id Test32(__weak ITest32 *x) {
595 __weak ITest32 *y;
596 x->ivar = 0; // expected-error {{dereferencing a __weak pointer is not allowed}}
597 return y ? y->ivar // expected-error {{dereferencing a __weak pointer is not allowed}}
598 : (*x).ivar; // expected-error {{dereferencing a __weak pointer is not allowed}}
599}
600
Fariborz Jahanian8295b7b2011-06-22 16:36:45 +0000601// rdar://9619861
602extern int printf(const char*, ...);
603typedef long intptr_t;
604
605int Test33(id someid) {
606 printf( "Hello%ld", (intptr_t)someid);
607 return (int)someid;
608}
609
Fariborz Jahanian831fb962011-06-25 00:17:46 +0000610// rdar://9636091
611@interface I34
612@property (nonatomic, retain) id newName __attribute__((ns_returns_not_retained)) ;
613
614@property (nonatomic, retain) id newName1 __attribute__((ns_returns_not_retained)) ;
615- (id) newName1 __attribute__((ns_returns_not_retained));
616
617@property (nonatomic, retain) id newName2 __attribute__((ns_returns_not_retained)); // expected-note {{roperty declared here}}
618- (id) newName2; // expected-warning {{property declared as returning non-retained objects; getter returning retained objects}}
619@end
620
621@implementation I34
622@synthesize newName;
623
624@synthesize newName1;
Fariborz Jahanian78980052011-08-01 22:39:49 +0000625- (id) newName1 { return 0; }
Fariborz Jahanian831fb962011-06-25 00:17:46 +0000626
Fariborz Jahanian78980052011-08-01 22:39:49 +0000627@synthesize newName2;
Fariborz Jahanian831fb962011-06-25 00:17:46 +0000628@end
629
John McCallc03fa492011-06-27 23:59:58 +0000630void test35(void) {
631 extern void test36_helper(id*);
632 id x;
633 __strong id *xp = 0;
634
635 test36_helper(&x);
636 test36_helper(xp); // expected-error {{passing address of non-local object to __autoreleasing parameter for write-back}}
637
638 // rdar://problem/9665710
639 __block id y;
640 test36_helper(&y);
641 ^{ test36_helper(&y); }();
Argyrios Kyrtzidis05d48762011-07-01 22:23:09 +0000642
643 __strong int non_objc_type; // expected-warning {{'__strong' only applies to objective-c object or block pointer types}}
John McCallc03fa492011-06-27 23:59:58 +0000644}
Douglas Gregorf96e9042011-07-12 17:28:52 +0000645
646void test36(int first, ...) {
647 // <rdar://problem/9758798>
648 __builtin_va_list arglist;
649 __builtin_va_start(arglist, first);
650 id obj = __builtin_va_arg(arglist, id);
651 __builtin_va_end(arglist);
652}
John McCall990567c2011-07-27 01:07:15 +0000653
Douglas Gregorb3029962011-11-14 22:10:01 +0000654@class Test37; // expected-note{{forward declaration of class here}}
John McCall990567c2011-07-27 01:07:15 +0000655void test37(Test37 *c) {
656 for (id y in c) { // expected-error {{collection expression type 'Test37' is a forward declaration}}
657 (void) y;
658 }
Argyrios Kyrtzidis5b76f372011-09-20 23:49:22 +0000659
660 (void)sizeof(id*); // no error.
John McCall990567c2011-07-27 01:07:15 +0000661}
John McCalla8e0cd82011-08-06 07:30:58 +0000662
663// rdar://problem/9887979
664@interface Test38
665@property int value;
666@end
667void test38() {
668 extern Test38 *test38_helper(void);
669 switch (test38_helper().value) {
670 case 0:
671 case 1:
672 ;
673 }
674}
Fariborz Jahanian175fb102011-10-03 22:11:57 +0000675
676// rdar://10186536
677@class NSColor;
678void _NSCalc(NSColor* color, NSColor* bezelColors[]) __attribute__((unavailable("not available in automatic reference counting mode")));
679
680void _NSCalcBeze(NSColor* color, NSColor* bezelColors[]); // expected-error {{must explicitly describe intended ownership of an object array parameter}}
Fariborz Jahaniana1de8cb2011-10-14 17:34:08 +0000681
682// rdar://9970739
683@interface RestaurantTableViewCell
684- (void) restaurantLocation;
685@end
686
687@interface Radar9970739
688- (void) Meth;
689@end
690
691@implementation Radar9970739
692- (void) Meth {
693 RestaurantTableViewCell *cell;
694 [cell restaurantLocatoin]; // expected-error {{no visible @interface for 'RestaurantTableViewCell' declares the selector 'restaurantLocatoin'}}
695}
696@end
697