1 // RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fobjc-runtime-has-weak -fsyntax-only -fobjc-arc -fblocks -verify -Wno-pointer-to-int-cast -Wno-objc-root-class %s
2 // RUN: not %clang_cc1 -triple x86_64-apple-darwin11 -fobjc-runtime-has-weak -fsyntax-only -fobjc-arc -fblocks -Wno-pointer-to-int-cast -Wno-objc-root-class -fdiagnostics-parseable-fixits %s 2>&1
4 typedef unsigned long NSUInteger;
5 typedef const void * CFTypeRef;
6 CFTypeRef CFBridgingRetain(id X);
7 id CFBridgingRelease(CFTypeRef);
8 @protocol NSCopying @end
9 @interface NSDictionary
10 + (id)dictionaryWithObjects:(const id [])objects forKeys:(const id <NSCopying> [])keys count:(NSUInteger)cnt;
11 - (void)setObject:(id)object forKeyedSubscript:(id)key;
13 @class NSFastEnumerationState;
14 @protocol NSFastEnumeration
15 - (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id __unsafe_unretained [])buffer count:(NSUInteger)len;
18 + (NSNumber *)numberWithInt:(int)value;
20 @interface NSArray <NSFastEnumeration>
21 + (id)arrayWithObjects:(const id [])objects count:(NSUInteger)cnt;
24 void test0(void (*fn)(int), int val) {
31 - (oneway void)release;
33 - (NSUInteger)retainCount;
37 SEL s = @selector(retain); // expected-error {{ARC forbids use of 'retain' in a @selector}}
38 s = @selector(release); // expected-error {{ARC forbids use of 'release' in a @selector}}
39 s = @selector(autorelease); // expected-error {{ARC forbids use of 'autorelease' in a @selector}}
40 s = @selector(dealloc); // expected-error {{ARC forbids use of 'dealloc' in a @selector}}
41 [a dealloc]; // expected-error {{ARC forbids explicit message send of 'dealloc'}}
42 [a retain]; // expected-error {{ARC forbids explicit message send of 'retain'}}
43 [a retainCount]; // expected-error {{ARC forbids explicit message send of 'retainCount'}}
44 [a release]; // expected-error {{ARC forbids explicit message send of 'release'}}
45 [a autorelease]; // expected-error {{ARC forbids explicit message send of 'autorelease'}}
53 // This should maybe just be ignored. We're just going to warn about it for now.
54 [super dealloc]; // expected-error {{ARC forbids explicit message send of 'dealloc'}}
59 - (id)retain; // expected-note {{method 'retain' declared here}}
60 - (id)autorelease; // expected-note {{method 'autorelease' declared here}}
61 - (oneway void)release; // expected-note {{method 'release' declared here}}
62 - (NSUInteger)retainCount; // expected-note {{method 'retainCount' declared here}}
66 - (id)retain{return 0;} // expected-error {{ARC forbids implementation of 'retain'}}
67 - (id)autorelease{return 0;} // expected-error {{ARC forbids implementation of 'autorelease'}}
68 - (oneway void)release{} // expected-error {{ARC forbids implementation of 'release'}}
69 - (NSUInteger)retainCount{ return 0; } // expected-error {{ARC forbids implementation of 'retainCount'}}
72 @implementation I(CAT)
73 - (id)retain{return 0;} // expected-error {{ARC forbids implementation of 'retain'}} \
74 // expected-warning {{category is implementing a method which will also be implemented by its primary class}}
75 - (id)autorelease{return 0;} // expected-error {{ARC forbids implementation of 'autorelease'}} \
76 // expected-warning {{category is implementing a method which will also be implemented by its primary class}}
77 - (oneway void)release{} // expected-error {{ARC forbids implementation of 'release'}} \
78 // expected-warning {{category is implementing a method which will also be implemented by its primary class}}
79 - (NSUInteger)retainCount{ return 0; } // expected-error {{ARC forbids implementation of 'retainCount'}} \
80 // expected-warning {{category is implementing a method which will also be implemented by its primary class}}
85 - (id)initWithInt: (int) i;
86 - (id)myInit __attribute__((objc_method_family(init)));
87 - (id)myBadInit __attribute__((objc_method_family(12))); // expected-error {{'objc_method_family' attribute requires parameter 1 to be an identifier}}
91 void rdar8861761(void) {
92 B *o1 = [[B alloc] initWithInt:0];
94 [o2 initWithInt:0]; // expected-warning {{expression result unused}}
95 B *o3 = [[B alloc] myInit];
96 [[B alloc] myInit]; // expected-warning {{expression result unused}}
99 @interface rdar8925835
100 - (void)foo:(void (^)(unsigned captureCount, I * const capturedStrings[captureCount]))block;
104 extern void test5_helper(__autoreleasing id *);
107 // Okay because of magic temporaries.
110 __autoreleasing id *a = &x; // expected-error {{initializing '__autoreleasing id *' with an expression of type '__strong id *' changes retain/release properties of pointer}}
112 __autoreleasing id *aa;
113 aa = &x; // expected-error {{assigning '__strong id *' to '__autoreleasing id *' changes retain/release properties of pointer}}
115 extern void test5_helper2(id const *);
118 extern void test5_helper3(__weak id *); // expected-note {{passing argument to parameter here}}
119 test5_helper3(&x); // expected-error {{passing '__strong id *' to parameter of type '__weak id *' changes retain/release properties of pointer}}
122 void test6(unsigned cond) {
126 id x; // expected-note {{jump bypasses initialization of __strong variable}}
128 case 1: // expected-error {{cannot jump}}
132 void test6a(unsigned cond) {
136 __weak id x; // expected-note {{jump bypasses initialization of __weak variable}}
138 case 1: // expected-error {{cannot jump}}
145 extern void test7_helper(NSError **);
149 void test7_weak(void) {
150 extern void test7_helper(NSError **);
154 void test7_unsafe(void) {
155 extern void test7_helper(NSError **); // expected-note {{passing argument to parameter here}}
156 __unsafe_unretained NSError *err;
157 test7_helper(&err); // expected-error {{passing 'NSError *__unsafe_unretained *' to parameter of type 'NSError *__autoreleasing *' changes retain/release properties of pointer}}
160 @class Test8_incomplete;
161 @interface Test8_complete @end;
162 @interface Test8_super @end;
163 @interface Test8 : Test8_super
165 - (id) init01; // expected-note {{declaration in interface}} \
166 // expected-note{{overridden method}}
167 - (id) init02; // expected-note{{overridden method}}
168 - (id) init03; // covariance
169 - (id) init04; // covariance
170 - (id) init05; // expected-note{{overridden method}}
172 - (void) init10; // expected-note {{declaration in interface is not in the 'init' family because its result type is not an object pointer}}
175 - (void) init13; // expected-note {{declaration in interface is not in the 'init' family because its result type is not an object pointer}}
176 - (void) init14; // expected-note {{declaration in interface is not in the 'init' family because its result type is not an object pointer}}
179 // These should be invalid to actually call.
180 - (Test8_incomplete*) init20;
181 - (Test8_incomplete*) init21; // expected-note {{declaration in interface}}
182 - (Test8_incomplete*) init22;
183 - (Test8_incomplete*) init23;
184 - (Test8_incomplete*) init24;
185 - (Test8_incomplete*) init25;
187 - (Test8_super*) init30; // id exception to covariance
188 - (Test8_super*) init31; // expected-note {{declaration in interface}} \
189 // expected-note{{overridden method}}
190 - (Test8_super*) init32; // expected-note{{overridden method}}
191 - (Test8_super*) init33;
192 - (Test8_super*) init34; // covariance
193 - (Test8_super*) init35; // expected-note{{overridden method}}
195 - (Test8*) init40; // id exception to covariance
196 - (Test8*) init41; // expected-note {{declaration in interface}} \
197 // expected-note{{overridden method}}
198 - (Test8*) init42; // expected-note{{overridden method}}
199 - (Test8*) init43; // this should be a warning, but that's a general language thing, not an ARC thing
201 - (Test8*) init45; // expected-note{{overridden method}}
203 - (Test8_complete*) init50; // expected-error {{init methods must return a type related to the receiver type}}
204 - (Test8_complete*) init51; // expected-error {{init methods must return a type related to the receiver type}}
205 - (Test8_complete*) init52; // expected-error {{init methods must return a type related to the receiver type}}
206 - (Test8_complete*) init53; // expected-error {{init methods must return a type related to the receiver type}}
207 - (Test8_complete*) init54; // expected-error {{init methods must return a type related to the receiver type}}
208 - (Test8_complete*) init55; // expected-error {{init methods must return a type related to the receiver type}}
210 @implementation Test8
211 - (id) init00 { return 0; }
212 - (id) init10 { return 0; } // expected-error {{method implementation does not match its declaration}}
213 - (id) init20 { return 0; }
214 - (id) init30 { return 0; }
215 - (id) init40 { return 0; }
216 - (id) init50 { return 0; }
218 - (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}} \
219 // expected-warning{{method is expected to return an instance of its class type 'Test8', but is declared to return 'void'}}
221 - (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}}
222 - (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}} \
223 // expected-warning{{method is expected to return an instance of its class type 'Test8', but is declared to return 'void'}}
224 - (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}} \
225 // expected-warning{{method is expected to return an instance of its class type 'Test8', but is declared to return 'void'}}
228 - (Test8_incomplete*) init02 { return 0; } // expected-error {{init methods must return a type related to the receiver type}} \
229 // expected-warning{{method is expected to return an instance of its class type 'Test8', but is declared to return 'Test8_incomplete *'}}
230 - (Test8_incomplete*) init12 { return 0; } // expected-error {{init methods must return a type related to the receiver type}}
231 - (Test8_incomplete*) init22 { return 0; } // expected-error {{init methods must return a type related to the receiver type}}
232 - (Test8_incomplete*) init32 { 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_incomplete *'}}
234 - (Test8_incomplete*) init42 { return 0; } // expected-error {{init methods must return a type related to the receiver type}} \
235 // expected-warning{{method is expected to return an instance of its class type 'Test8', but is declared to return 'Test8_incomplete *'}}
236 - (Test8_incomplete*) init52 { return 0; } // expected-error {{init methods must return a type related to the receiver type}}
238 - (Test8_super*) init03 { return 0; }
239 - (Test8_super*) init13 { return 0; } // expected-error {{method implementation does not match its declaration}}
240 - (Test8_super*) init23 { return 0; }
241 - (Test8_super*) init33 { return 0; }
242 - (Test8_super*) init43 { return 0; }
243 - (Test8_super*) init53 { return 0; }
245 - (Test8*) init04 { return 0; }
246 - (Test8*) init14 { return 0; } // expected-error {{method implementation does not match its declaration}}
247 - (Test8*) init24 { return 0; }
248 - (Test8*) init34 { return 0; }
249 - (Test8*) init44 { return 0; }
250 - (Test8*) init54 { return 0; }
252 - (Test8_complete*) init05 { return 0; } // expected-error {{init methods must return a type related to the receiver type}} \
253 // expected-warning{{method is expected to return an instance of its class type 'Test8', but is declared to return 'Test8_complete *'}}
254 - (Test8_complete*) init15 { return 0; } // expected-error {{init methods must return a type related to the receiver type}}
255 - (Test8_complete*) init25 { return 0; } // expected-error {{init methods must return a type related to the receiver type}}
256 - (Test8_complete*) init35 { return 0; } // expected-error {{init methods must return a type related to the receiver type}} \
257 // expected-warning{{method is expected to return an instance of its class type 'Test8', but is declared to return 'Test8_complete *'}}
258 - (Test8_complete*) init45 { return 0; } // expected-error {{init methods must return a type related to the receiver type}} \
259 // expected-warning{{method is expected to return an instance of its class type 'Test8', but is declared to return 'Test8_complete *'}}
260 - (Test8_complete*) init55 { return 0; } // expected-error {{init methods must return a type related to the receiver type}}
263 @class Test9_incomplete;
265 - (Test9_incomplete*) init1; // expected-error {{init methods must return a type related to the receiver type}}
266 - (Test9_incomplete*) init2;
272 // Test that the inference rules are different for fast enumeration variables.
273 void test10(id collection) {
274 for (id x in collection) {
275 __strong id *ptr = &x; // expected-warning {{initializing '__strong id *' with an expression of type 'const __strong id *' discards qualifiers}}
278 for (__strong id x in collection) {
279 __weak id *ptr = &x; // expected-error {{initializing '__weak id *' with an expression of type '__strong id *' changes retain/release properties of pointer}}
283 #define nil ((void*) 0)
284 void test11(id op, void *vp) {
292 // FIXME: Shouldn't these be consistent?
293 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}}
297 void test12(id collection) {
298 for (id x in collection) {
299 x = 0; // expected-error {{fast enumeration variables cannot be modified in ARC by default; declare the variable __strong to allow this}}
302 for (const id x in collection) { // expected-note {{variable 'x' declared const here}}
303 x = 0; // expected-error {{cannot assign to variable 'x' with const-qualified type 'const __strong id'}}
306 for (__strong id x in collection) {
315 @implementation Test13
320 self = 0; // expected-error {{cannot assign to 'self' outside of a method in the init family}}
325 - (id) consumesSelf __attribute__((ns_consumes_self));
327 @implementation Test13_B
328 - (id) consumesSelf {
329 self = 0; // no-warning
333 @class Test14A, Test14B;
335 extern void test14_consume(id *);
336 extern int test14_cond(void);
337 extern float test14_nowriteback(id __autoreleasing const *); // expected-note{{passing argument to parameter here}}
343 id vla[test14_cond() + 10];
345 test14_consume((__strong id*) &a);
346 test14_consume((test14_cond() ? (__strong id*) &b : &i));
347 test14_consume(test14_cond() ? 0 : &a);
348 test14_consume(test14_cond() ? (void*) 0 : (&a));
349 test14_consume(cla); // expected-error {{passing address of non-scalar object to __autoreleasing parameter for write-back}}
350 test14_consume(vla); // expected-error {{passing address of non-scalar object to __autoreleasing parameter for write-back}}
351 test14_consume(&cla[5]); // expected-error {{passing address of non-scalar object to __autoreleasing parameter for write-back}}
353 __strong id *test14_indirect(void);
354 test14_consume(test14_indirect()); // expected-error {{passing address of non-local object to __autoreleasing parameter for write-back}}
356 extern id test14_global;
357 test14_consume(&test14_global); // expected-error {{passing address of non-local object to __autoreleasing parameter for write-back}}
359 extern __strong id *test14_global_ptr;
360 test14_consume(test14_global_ptr); // expected-error {{passing address of non-local object to __autoreleasing parameter for write-back}}
362 static id static_local;
363 test14_consume(&static_local); // expected-error {{passing address of non-local object to __autoreleasing parameter for write-back}}
366 test14_nowriteback(&static_local); // okay, not a write-back.
367 test14_nowriteback(wip); // expected-error{{passing '__weak id *' to parameter of type '__autoreleasing id const *' changes retain/release properties of pointer}}
371 __block __autoreleasing id x; // expected-error {{__block variables cannot have __autoreleasing ownership}}
376 - (void) test16_0: (int) x;
377 - (int) test16_1: (int) x; // expected-note {{one possibility}}
378 - (int) test16_2: (int) x; // expected-note {{one possibility}}
379 - (id) test16_3: (int) x __attribute__((ns_returns_retained)); // expected-note {{one possibility}}
380 - (void) test16_4: (int) x __attribute__((ns_consumes_self)); // expected-note {{one possibility}}
381 - (void) test16_5: (id) __attribute__((ns_consumed)) x; // expected-note {{one possibility}}
382 - (void) test16_6: (id) x;
386 - (void) test16_0: (int) x;
387 - (int) test16_1: (char*) x; // expected-note {{also found}}
388 - (char*) test16_2: (int) x; // expected-note {{also found}}
389 - (id) test16_3: (int) x; // expected-note {{also found}}
390 - (void) test16_4: (int) x; // expected-note {{also found}}
391 - (void) test16_5: (id) x; // expected-note {{also found}}
392 - (void) test16_6: (struct Test16 *) x;
398 [v test16_1: 0]; // expected-error {{multiple methods named 'test16_1:' found with mismatched result, parameter type or attributes}}
399 [v test16_2: 0]; // expected-error {{multiple methods named}}
400 [v test16_3: 0]; // expected-error {{multiple methods named}}
401 [v test16_4: 0]; // expected-error {{multiple methods named}}
402 [v test16_5: 0]; // expected-error {{multiple methods named}}
406 @class Test17; // expected-note 3{{forward declaration of class here}}
413 [v0 test17]; // expected-error {{receiver type 'Test17' for instance message is a forward declaration}}
416 [v1 test17]; // expected-error {{receiver type 'Test17<Test17p>' for instance message is a forward declaration}}
418 [Test17 test17]; // expected-error {{receiver 'Test17' for class message is a forward declaration}}
423 [x test18]; // expected-error {{instance method 'test18' not found ; did you mean 'test17'?}}
426 extern struct Test19 *test19a;
427 struct Test19 *const test19b = 0;
430 x = (id) test19a; // expected-error {{bridged cast}} \
431 // expected-note{{use __bridge to convert directly (no change in ownership)}} \
432 // expected-note{{use CFBridgingRelease call to transfer ownership of a +1 'struct Test19 *' into ARC}}
433 x = (id) test19b; // expected-error {{bridged cast}} \
434 // expected-note{{use __bridge to convert directly (no change in ownership)}} \
435 // expected-note{{use CFBridgingRelease call to transfer ownership of a +1 'struct Test19 *' into ARC}}
438 static __thread id test20_implicit; // expected-error {{thread-local variable has non-trivial ownership: type is '__strong id'}}
439 static __thread __strong id test20_strong; // expected-error {{thread-local variable has non-trivial ownership: type is '__strong id'}}
440 static __thread __weak id test20_weak; // expected-error {{thread-local variable has non-trivial ownership: type is '__weak id'}}
441 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}}
442 static __thread __unsafe_unretained id test20_unsafe;
444 static __thread id test20_implicit; // expected-error {{thread-local variable has non-trivial ownership: type is '__strong id'}}
445 static __thread __strong id test20_strong; // expected-error {{thread-local variable has non-trivial ownership: type is '__strong id'}}
446 static __thread __weak id test20_weak; // expected-error {{thread-local variable has non-trivial ownership: type is '__weak id'}}
447 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}}
448 static __thread __unsafe_unretained id test20_unsafe;
455 // Check casting w/ ownership qualifiers.
458 (void)(__weak id *)sip; // expected-error{{casting '__strong id *' to type '__weak id *' changes retain/release properties of pointer}}
459 (void)(__weak const id *)sip; // expected-error{{casting '__strong id *' to type '__weak id const *' changes retain/release properties of pointer}}
460 (void)(__autoreleasing id *)sip; // expected-error{{casting '__strong id *' to type '__autoreleasing id *' changes retain/release properties of pointer}}
461 (void)(__autoreleasing const id *)sip; // okay
464 void test22(id x[]) { // expected-error {{must explicitly describe intended ownership of an object array parameter}}
470 ptr = (ptr ? @"foo" : 0);
471 ptr = (ptr ? @"foo" : @"bar");
475 extern void test24_helper(void);
476 return test24_helper(), (void*) 0;
480 @property (assign) id content;
483 @interface Foo : Base
493 void test25(Class *classes) {
494 Class *other_classes;
495 test25(other_classes);
499 extern id test26_var1;
500 __sync_swap(&test26_var1, 0, y); // expected-error {{cannot perform atomic operation on a pointer to type '__strong id': type has non-trivial ownership}}
502 extern __unsafe_unretained id test26_var2;
503 __sync_swap(&test26_var2, 0, y);
508 - (id) initWithInt: (int) x;
510 @implementation Test26
511 - (id) init { return self; }
512 - (id) initWithInt: (int) x {
513 [self init]; // expected-error {{the result of a delegate init call must be immediately returned or assigned to 'self'}}
523 @property (readonly) id ro;
524 @property (readonly) id custom_ro;
527 @property (readonly) __weak id myProp1;
528 @property (readonly) id myProp2;
529 @property (readonly) __strong id myProp3;
532 @implementation Test27
537 @synthesize myProp1 = _myProp1;
541 -(id)custom_ro { return 0; }
545 @property (nonatomic, assign) __strong id a; // expected-error {{unsafe_unretained property 'a' may not also be declared __strong}}
549 @property (nonatomic, assign) __strong id b; // expected-error {{unsafe_unretained property 'b' may not also be declared __strong}}
552 @implementation Test28
557 typedef struct Bark Bark;
562 @implementation Test29
575 @implementation Test30
576 + (id) new { return 0; }
578 __weak id x = [Test30 new]; // expected-warning {{assigning retained object to weak variable}}
579 id __unsafe_unretained u = [Test30 new]; // expected-warning {{assigning retained object to unsafe_unretained variable}}
581 x = [Test30 new]; // expected-warning {{assigning retained object to weak variable}}
582 u = [Test30 new]; // expected-warning {{assigning retained object to unsafe_unretained variable}}
587 @protocol PTest31 @end
595 int i = (ids->isa ? 1 : 0); // expected-error {{member reference base type 'id' is not a structure or union}}
596 int j = (pids->isa ? 1 : 0); // expected-error {{member reference base type 'id<PTest31>' is not a structure or union}}
597 int k = (pcls->isa ? i : j); // expected-error {{member reference base type 'Class<PTest31>' is not a structure or union}}
598 return cls->isa ? i : j; // expected-error {{member reference base type 'Class' is not a structure or union}}
607 id Test32(__weak ITest32 *x) {
609 x->ivar = 0; // expected-error {{dereferencing a __weak pointer is not allowed}}
610 return y ? y->ivar // expected-error {{dereferencing a __weak pointer is not allowed}}
611 : (*x).ivar; // expected-error {{dereferencing a __weak pointer is not allowed}}
614 extern int printf(const char*, ...);
615 typedef long intptr_t;
617 int Test33(id someid) {
618 printf( "Hello%ld", (intptr_t)someid);
623 @property (nonatomic, retain) id newName __attribute__((ns_returns_not_retained)) ;
625 @property (nonatomic, retain) id newName1 __attribute__((ns_returns_not_retained)) ;
626 - (id) newName1 __attribute__((ns_returns_not_retained));
628 @property (nonatomic, retain) id newName2 __attribute__((ns_returns_not_retained)); // expected-note {{roperty declared here}}
629 - (id) newName2; // expected-warning {{property declared as returning non-retained objects; getter returning retained objects}}
635 @synthesize newName1;
636 - (id) newName1 { return 0; }
638 @synthesize newName2;
642 extern void test36_helper(id*);
647 test36_helper(xp); // expected-error {{passing address of non-local object to __autoreleasing parameter for write-back}}
651 ^{ test36_helper(&y); }();
653 __strong int non_objc_type; // expected-warning {{'__strong' only applies to Objective-C object or block pointer types}}
656 void test36(int first, ...) {
657 __builtin_va_list arglist;
658 __builtin_va_start(arglist, first);
659 id obj = __builtin_va_arg(arglist, id);
660 __builtin_va_end(arglist);
663 @class Test37; // expected-note{{forward declaration of class here}}
664 void test37(Test37 *c) {
665 for (id y in c) { // expected-error {{collection expression type 'Test37' is a forward declaration}}
669 (void)sizeof(id*); // no error.
676 extern Test38 *test38_helper(void);
677 switch (test38_helper().value) {
685 void _NSCalc(NSColor* color, NSColor* bezelColors[]) __attribute__((unavailable("not available in automatic reference counting mode")));
687 void _NSCalcBeze(NSColor* color, NSColor* bezelColors[]); // expected-error {{must explicitly describe intended ownership of an object array parameter}}
689 @interface RestaurantTableViewCell
690 - (void) restaurantLocation;
693 @interface Radar9970739
697 @implementation Radar9970739
699 RestaurantTableViewCell *cell;
700 [cell restaurantLocatoin]; // expected-error {{no visible @interface for 'RestaurantTableViewCell' declares the selector 'restaurantLocatoin'}}
704 @interface Radar11814185
705 @property (nonatomic, weak) Radar11814185* picker1;
710 @implementation Radar11814185
716 picker1 = [[Radar11814185 alloc] init]; // expected-warning {{assigning retained object to weak variable; object will be released after assignment}}
717 self.picker1 = [[Radar11814185 alloc] init]; // expected-warning {{assigning retained object to weak property; object will be released after assignment}}
720 + alloc { return 0; }
724 // Warn on cases of initializing a weak variable with an Objective-C object
726 void rdar12569201(id key, id value) {
728 __weak id x = @"foo"; // no-warning
729 __weak id y = @{ key : value }; // expected-warning {{assigning dictionary literal to a weak variable; object will be released after assignment}}
730 __weak id z = @[ value ]; // expected-warning {{assigning array literal to a weak variable; object will be released after assignment}}
731 __weak id b = ^() {}; // expected-warning {{assigning block literal to a weak variable; object will be released after assignment}}
732 __weak id n = @42; // expected-warning {{assigning numeric literal to a weak variable; object will be released after assignment}}
733 __weak id e = @(42); // expected-warning {{assigning numeric literal to a weak variable; object will be released after assignment}}
734 __weak id m = @(41 + 1); // expected-warning {{assigning boxed expression to a weak variable; object will be released after assignment}}
737 y = @{ key : value }; // expected-warning {{assigning dictionary literal to a weak variable; object will be released after assignment}}
738 z = @[ value ]; // expected-warning {{assigning array literal to a weak variable; object will be released after assignment}}
739 b = ^() {}; // expected-warning {{assigning block literal to a weak variable; object will be released after assignment}}
740 n = @42; // expected-warning {{assigning numeric literal to a weak variable; object will be released after assignment}}
741 e = @(42); // expected-warning {{assigning numeric literal to a weak variable; object will be released after assignment}}
742 m = @(41 + 1); // expected-warning {{assigning boxed expression to a weak variable; object will be released after assignment}}
746 - (void)method:(id[])objects; // expected-error{{must explicitly describe intended ownership of an object array parameter}}
749 @interface NSMutableArray : NSArray @end
751 typedef __strong NSMutableArray * PSNS;
753 void test(NSArray *x) {
754 NSMutableArray *y = x; // expected-warning {{incompatible pointer types initializing 'NSMutableArray *' with an expression of type 'NSArray *'}}
755 __strong NSMutableArray *y1 = x; // expected-warning {{incompatible pointer types initializing 'NSMutableArray *' with an expression of type 'NSArray *'}}
756 PSNS y2 = x; // expected-warning {{incompatible pointer types initializing 'NSMutableArray *' with an expression of type 'NSArray *'}}
761 void foo(NSArray *array) {
762 for (NSString *string in array) {
763 for (string in @[@"blah", @"more blah", string]) { // expected-error {{selector element of type 'NSString *const __strong' cannot be a constant lvalue}}
768 extern void abort(void);
769 #define TKAssertEqual(a, b) do{\
770 __typeof(a) a_res = (a);\
771 __typeof(b) b_res = (b);\
772 if ((a_res) != (b_res)) {\
779 TKAssertEqual(object, nil);
780 TKAssertEqual(object, (id)nil);
783 void block_capture_autoreleasing(A * __autoreleasing *a,
784 A **b, // expected-note {{declare the parameter __strong or capture a __block __strong variable to keep values alive across autorelease pools}}
785 A * _Nullable *c, // expected-note {{declare the parameter __strong or capture a __block __strong variable to keep values alive across autorelease pools}}
786 A * _Nullable __autoreleasing *d,
787 A ** _Nullable e, // expected-note {{declare the parameter __strong or capture a __block __strong variable to keep values alive across autorelease pools}}
788 A * __autoreleasing * _Nullable f,
789 id __autoreleasing *g,
790 id *h, // expected-note {{declare the parameter __strong or capture a __block __strong variable to keep values alive across autorelease pools}}
791 id _Nullable *i, // expected-note {{declare the parameter __strong or capture a __block __strong variable to keep values alive across autorelease pools}}
792 id _Nullable __autoreleasing *j,
793 id * _Nullable k, // expected-note {{declare the parameter __strong or capture a __block __strong variable to keep values alive across autorelease pools}}
794 id __autoreleasing * _Nullable l) {
797 (void)*b; // expected-warning {{block captures an autoreleasing out-parameter, which may result in use-after-free bugs}}
798 (void)*c; // expected-warning {{block captures an autoreleasing out-parameter, which may result in use-after-free bugs}}
800 (void)*e; // expected-warning {{block captures an autoreleasing out-parameter, which may result in use-after-free bugs}}
803 (void)*h; // expected-warning {{block captures an autoreleasing out-parameter, which may result in use-after-free bugs}}
804 (void)*i; // expected-warning {{block captures an autoreleasing out-parameter, which may result in use-after-free bugs}}
806 (void)*k; // expected-warning {{block captures an autoreleasing out-parameter, which may result in use-after-free bugs}}
811 void test_vla_fold_keeps_strong(void) {
812 const unsigned bounds = 1;
814 static id array[bounds]; // expected-warning {{variable length array folded to constant array as an extension}}
815 typedef __typeof__(array) array_type;
816 typedef id __strong array_type[1];
818 static id weak_array[bounds] __weak; // expected-warning {{variable length array folded to constant array as an extension}}
819 typedef __typeof__(weak_array) weak_array_type;
820 typedef id __weak weak_array_type[1];