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