blob: 824fc08aec5c6c2cf0feee517f01c1f6930b7dbb [file] [log] [blame]
John McCall9f084a32011-07-06 00:26:06 +00001// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fobjc-nonfragile-abi -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
266 b = (vp == op); // expected-error {{implicit conversion of an Objective-C pointer to 'void *'}}
267 b = (op == vp); // expected-error {{implicit conversion of a non-Objective-C pointer type 'void *' to 'id'}}
268}
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
297// rdar://problem/9172151
298@class Test14A, Test14B;
299void test14() {
300 extern void test14_consume(id *);
301 extern int test14_cond(void);
302 extern float test14_nowriteback(id __autoreleasing const *); // expected-note{{passing argument to parameter here}}
303
304 Test14A *a;
305 Test14B *b;
306 id i;
307 id cla[10];
308 id vla[test14_cond() + 10];
309
310 test14_consume((__strong id*) &a);
311 test14_consume((test14_cond() ? (__strong id*) &b : &i));
312 test14_consume(test14_cond() ? 0 : &a);
313 test14_consume(test14_cond() ? (void*) 0 : (&a));
314 test14_consume(cla); // expected-error {{passing address of non-scalar object to __autoreleasing parameter for write-back}}
315 test14_consume(vla); // expected-error {{passing address of non-scalar object to __autoreleasing parameter for write-back}}
316 test14_consume(&cla[5]); // expected-error {{passing address of non-scalar object to __autoreleasing parameter for write-back}}
317
318 __strong id *test14_indirect(void);
319 test14_consume(test14_indirect()); // expected-error {{passing address of non-local object to __autoreleasing parameter for write-back}}
320
321 extern id test14_global;
322 test14_consume(&test14_global); // expected-error {{passing address of non-local object to __autoreleasing parameter for write-back}}
323
324 extern __strong id *test14_global_ptr;
325 test14_consume(test14_global_ptr); // expected-error {{passing address of non-local object to __autoreleasing parameter for write-back}}
326
327 static id static_local;
328 test14_consume(&static_local); // expected-error {{passing address of non-local object to __autoreleasing parameter for write-back}}
329
330 __weak id* wip;
331 test14_nowriteback(&static_local); // okay, not a write-back.
332 test14_nowriteback(wip); // expected-error{{passing '__weak id *' to parameter of type '__autoreleasing id const *' changes retain/release properties of pointer}}
333}
334
335void test15() {
Argyrios Kyrtzidisb8b03132011-06-24 00:08:59 +0000336 __block __autoreleasing id x; // expected-error {{__block variables cannot have __autoreleasing ownership}}
John McCallf85e1932011-06-15 23:02:42 +0000337}
338
339struct Test16;
340@interface Test16a
341- (void) test16_0: (int) x;
342- (int) test16_1: (int) x; // expected-note {{one possibility}}
343- (int) test16_2: (int) x; // expected-note {{one possibility}}
344- (id) test16_3: (int) x __attribute__((ns_returns_retained)); // expected-note {{one possibility}}
345- (void) test16_4: (int) x __attribute__((ns_consumes_self)); // expected-note {{one possibility}}
346- (void) test16_5: (id) __attribute__((ns_consumed)) x; // expected-note {{one possibility}}
347- (void) test16_6: (id) x;
348@end
349
350@interface Test16b
351- (void) test16_0: (int) x;
352- (int) test16_1: (char*) x; // expected-note {{also found}}
353- (char*) test16_2: (int) x; // expected-note {{also found}}
354- (id) test16_3: (int) x; // expected-note {{also found}}
355- (void) test16_4: (int) x; // expected-note {{also found}}
356- (void) test16_5: (id) x; // expected-note {{also found}}
357- (void) test16_6: (struct Test16 *) x;
358@end
359
360void test16(void) {
361 id v;
362 [v test16_0: 0];
363 [v test16_1: 0]; // expected-error {{multiple methods named 'test16_1:' found with mismatched result, parameter type or attributes}}
364 [v test16_2: 0]; // expected-error {{multiple methods named}}
365 [v test16_3: 0]; // expected-error {{multiple methods named}}
366 [v test16_4: 0]; // expected-error {{multiple methods named}}
367 [v test16_5: 0]; // expected-error {{multiple methods named}}
368 [v test16_6: 0];
369}
370
371@class Test17;
372@protocol Test17p
373- (void) test17;
374+ (void) test17;
375@end
376void test17(void) {
377 Test17 *v0;
378 [v0 test17]; // expected-error {{receiver type 'Test17' for instance message is a forward declaration}}
379
380 Test17<Test17p> *v1;
381 [v1 test17]; // expected-error {{receiver type 'Test17<Test17p>' for instance message is a forward declaration}}
382
383 [Test17 test17]; // expected-error {{receiver 'Test17' for class message is a forward declaration}}
384}
385
386void test18(void) {
387 id x;
388 [x test18]; // expected-error {{no known instance method for selector 'test18'}}
389}
390
391extern struct Test19 *test19a;
392struct Test19 *const test19b = 0;
393void test19(void) {
394 id x;
395 x = (id) test19a; // expected-error {{bridged cast}} \
396 // expected-note{{use __bridge to convert directly (no change in ownership))}} \
397 // expected-note{{use __bridge_transfer to transfer ownership of a +1 'struct Test19 *' into ARC}}
398 x = (id) test19b; // expected-error {{bridged cast}} \
399 // expected-note{{use __bridge to convert directly (no change in ownership)}} \
400 // expected-note{{use __bridge_transfer to transfer ownership of a +1 'struct Test19 *' into ARC}}
401}
402
403// rdar://problem/8951453
Argyrios Kyrtzidisb8b03132011-06-24 00:08:59 +0000404static __thread id test20_implicit; // expected-error {{thread-local variable has non-trivial ownership: type is '__strong id'}}
405static __thread __strong id test20_strong; // expected-error {{thread-local variable has non-trivial ownership: type is '__strong id'}}
406static __thread __weak id test20_weak; // expected-error {{thread-local variable has non-trivial ownership: type is '__weak id'}}
407static __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 +0000408static __thread __unsafe_unretained id test20_unsafe;
409void test20(void) {
Argyrios Kyrtzidisb8b03132011-06-24 00:08:59 +0000410 static __thread id test20_implicit; // expected-error {{thread-local variable has non-trivial ownership: type is '__strong id'}}
411 static __thread __strong id test20_strong; // expected-error {{thread-local variable has non-trivial ownership: type is '__strong id'}}
412 static __thread __weak id test20_weak; // expected-error {{thread-local variable has non-trivial ownership: type is '__weak id'}}
413 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 +0000414 static __thread __unsafe_unretained id test20_unsafe;
415}
416
417// rdar://9310049
418_Bool fn(id obj) {
419 return (_Bool)obj;
420}
421
Argyrios Kyrtzidisb8b03132011-06-24 00:08:59 +0000422// Check casting w/ ownership qualifiers.
John McCallf85e1932011-06-15 23:02:42 +0000423void test21() {
424 __strong id *sip;
425 (void)(__weak id *)sip; // expected-error{{casting '__strong id *' to type '__weak id *' changes retain/release properties of pointer}}
426 (void)(__weak const id *)sip; // expected-error{{casting '__strong id *' to type '__weak id const *' changes retain/release properties of pointer}}
427 (void)(__autoreleasing id *)sip; // expected-error{{casting '__strong id *' to type '__autoreleasing id *' changes retain/release properties of pointer}}
428 (void)(__autoreleasing const id *)sip; // okay
429}
430
431// rdar://problem/9340462
Argyrios Kyrtzidisb8b03132011-06-24 00:08:59 +0000432void test22(id x[]) { // expected-error {{must explicitly describe intended ownership of an object array parameter}}
John McCallf85e1932011-06-15 23:02:42 +0000433}
434
435// rdar://problem/9400219
436void test23(void) {
437 void *ptr;
438 ptr = @"foo";
439 ptr = (ptr ? @"foo" : 0);
440 ptr = (ptr ? @"foo" : @"bar");
441}
442
443id test24(void) {
444 extern void test24_helper(void);
445 return test24_helper(), (void*) 0;
446}
447
448// rdar://9400841
449@interface Base
450@property (assign) id content;
451@end
452
453@interface Foo : Base
454-(void)test;
455@end
456
457@implementation Foo
458-(void)test {
459 super.content = 0;
460}
461@end
462
463// <rdar://problem/9398437>
464void test25(Class *classes) {
465 Class *other_classes;
466 test25(other_classes);
467}
468
469void test26(id y) {
470 extern id test26_var1;
Argyrios Kyrtzidisb8b03132011-06-24 00:08:59 +0000471 __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 +0000472
473 extern __unsafe_unretained id test26_var2;
474 __sync_swap(&test26_var2, 0, y);
475}
476
477@interface Test26
478- (id) init;
479- (id) initWithInt: (int) x;
480@end
481@implementation Test26
482- (id) init { return self; }
483- (id) initWithInt: (int) x {
484 [self init]; // expected-error {{the result of a delegate init call must be immediately returned or assigned to 'self'}}
485 return self;
486}
487@end
488
489// rdar://9525555
Argyrios Kyrtzidis473506b2011-07-26 21:48:26 +0000490@interface Test27 {
491 __weak id _myProp1;
492 id myProp2;
493}
Argyrios Kyrtzidis0a68dc72011-07-12 04:30:16 +0000494@property id x; // expected-warning {{no 'assign', 'retain', or 'copy' attribute is specified - 'assign' is assumed}} \
495 // expected-warning {{default property attribute 'assign' not appropriate for non-gc object}} \
496 // expected-note {{declared here}}
497@property (readonly) id ro; // expected-note {{declared here}}
498@property (readonly) id custom_ro;
John McCallf85e1932011-06-15 23:02:42 +0000499@property int y;
Argyrios Kyrtzidis473506b2011-07-26 21:48:26 +0000500
501@property (readonly) id myProp1;
502@property (readonly) id myProp2;
503@property (readonly) __strong id myProp3;
John McCallf85e1932011-06-15 23:02:42 +0000504@end
505
Argyrios Kyrtzidis0a68dc72011-07-12 04:30:16 +0000506@implementation Test27
Argyrios Kyrtzidis473506b2011-07-26 21:48:26 +0000507@synthesize x; // expected-error {{ARC forbids synthesizing a property of an Objective-C object with unspecified ownership or storage attribute}}
508@synthesize ro; // expected-error {{ARC forbids synthesizing a property of an Objective-C object with unspecified ownership or storage attribute}}
Argyrios Kyrtzidis0a68dc72011-07-12 04:30:16 +0000509@synthesize y;
Argyrios Kyrtzidis473506b2011-07-26 21:48:26 +0000510
511@synthesize myProp1 = _myProp1;
512@synthesize myProp2;
513@synthesize myProp3;
514
Argyrios Kyrtzidis0a68dc72011-07-12 04:30:16 +0000515-(id)custom_ro { return 0; }
516@end
517
John McCallf85e1932011-06-15 23:02:42 +0000518// rdar://9569264
519@interface Test28
520@property (nonatomic, assign) __strong id a; // expected-error {{unsafe_unretained property 'a' may not also be declared __strong}}
521@end
522
523@interface Test28 ()
524@property (nonatomic, assign) __strong id b; // expected-error {{unsafe_unretained property 'b' may not also be declared __strong}}
525@end
526
527@implementation Test28
528@synthesize a;
529@synthesize b;
530@end
531
532// rdar://9573962
533typedef struct Bark Bark;
534@interface Test29
535@property Bark* P;
536@end
537
538@implementation Test29
539@synthesize P;
540- (id)Meth {
541 Bark** f = &P;
542 return 0;
543}
544@end
545
546// rdar://9495837
547@interface Test30
Fariborz Jahanian921c1432011-06-24 18:25:34 +0000548+ (id) new;
John McCallf85e1932011-06-15 23:02:42 +0000549- (void)Meth;
550@end
551
552@implementation Test30
Fariborz Jahanian921c1432011-06-24 18:25:34 +0000553+ (id) new { return 0; }
John McCallf85e1932011-06-15 23:02:42 +0000554- (void) Meth {
Argyrios Kyrtzidisd26fef02011-06-22 18:03:53 +0000555 __weak id x = [Test30 new]; // expected-warning {{assigning retained object to weak variable}}
556 id __unsafe_unretained u = [Test30 new]; // expected-warning {{assigning retained object to unsafe_unretained variable}}
John McCallf85e1932011-06-15 23:02:42 +0000557 id y = [Test30 new];
Argyrios Kyrtzidisd26fef02011-06-22 18:03:53 +0000558 x = [Test30 new]; // expected-warning {{assigning retained object to weak variable}}
559 u = [Test30 new]; // expected-warning {{assigning retained object to unsafe_unretained variable}}
John McCallf85e1932011-06-15 23:02:42 +0000560 y = [Test30 new];
561}
562@end
563
564// rdar://9411838
565@protocol PTest31 @end
566
567int Test31() {
568 Class cls;
569 id ids;
570 id<PTest31> pids;
571 Class<PTest31> pcls;
572
573 int i = (ids->isa ? 1 : 0); // expected-error {{member reference base type 'id' is not a structure or union}}
574 int j = (pids->isa ? 1 : 0); // expected-error {{member reference base type 'id<PTest31>' is not a structure or union}}
575 int k = (pcls->isa ? i : j); // expected-error {{member reference base type 'Class<PTest31>' is not a structure or union}}
576 return cls->isa ? i : j; // expected-error {{member reference base type 'Class' is not a structure or union}}
577}
Fariborz Jahanianb1f7d242011-06-16 17:29:56 +0000578
579// rdar://9612030
580@interface ITest32 {
581@public
582 id ivar;
583}
584@end
585
586id Test32(__weak ITest32 *x) {
587 __weak ITest32 *y;
588 x->ivar = 0; // expected-error {{dereferencing a __weak pointer is not allowed}}
589 return y ? y->ivar // expected-error {{dereferencing a __weak pointer is not allowed}}
590 : (*x).ivar; // expected-error {{dereferencing a __weak pointer is not allowed}}
591}
592
Fariborz Jahanian8295b7b2011-06-22 16:36:45 +0000593// rdar://9619861
594extern int printf(const char*, ...);
595typedef long intptr_t;
596
597int Test33(id someid) {
598 printf( "Hello%ld", (intptr_t)someid);
599 return (int)someid;
600}
601
Fariborz Jahanian831fb962011-06-25 00:17:46 +0000602// rdar://9636091
603@interface I34
604@property (nonatomic, retain) id newName __attribute__((ns_returns_not_retained)) ;
605
606@property (nonatomic, retain) id newName1 __attribute__((ns_returns_not_retained)) ;
607- (id) newName1 __attribute__((ns_returns_not_retained));
608
609@property (nonatomic, retain) id newName2 __attribute__((ns_returns_not_retained)); // expected-note {{roperty declared here}}
610- (id) newName2; // expected-warning {{property declared as returning non-retained objects; getter returning retained objects}}
611@end
612
613@implementation I34
614@synthesize newName;
615
616@synthesize newName1;
Fariborz Jahanian527eec82011-07-22 01:06:53 +0000617- (id) newName1 { return 0; } // expected-note {{method declared here}}
Fariborz Jahanian831fb962011-06-25 00:17:46 +0000618
Fariborz Jahanian527eec82011-07-22 01:06:53 +0000619@synthesize newName2; // expected-error {{property implementation declaration after method or function definition}}
Fariborz Jahanian831fb962011-06-25 00:17:46 +0000620@end
621
John McCallc03fa492011-06-27 23:59:58 +0000622void test35(void) {
623 extern void test36_helper(id*);
624 id x;
625 __strong id *xp = 0;
626
627 test36_helper(&x);
628 test36_helper(xp); // expected-error {{passing address of non-local object to __autoreleasing parameter for write-back}}
629
630 // rdar://problem/9665710
631 __block id y;
632 test36_helper(&y);
633 ^{ test36_helper(&y); }();
Argyrios Kyrtzidis05d48762011-07-01 22:23:09 +0000634
635 __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 +0000636}
Douglas Gregorf96e9042011-07-12 17:28:52 +0000637
638void test36(int first, ...) {
639 // <rdar://problem/9758798>
640 __builtin_va_list arglist;
641 __builtin_va_start(arglist, first);
642 id obj = __builtin_va_arg(arglist, id);
643 __builtin_va_end(arglist);
644}
John McCall990567c2011-07-27 01:07:15 +0000645
646@class Test37;
647void test37(Test37 *c) {
648 for (id y in c) { // expected-error {{collection expression type 'Test37' is a forward declaration}}
649 (void) y;
650 }
651}