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 // RUN: not %clang_cc1 -triple x86_64-apple-darwin11 -fobjc-runtime-has-weak -fsyntax-only -fobjc-arc -fblocks -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'}}
61 - (id)retain; // expected-note {{method 'retain' declared here}}
62 - (id)autorelease; // expected-note {{method 'autorelease' declared here}}
63 - (oneway void)release; // expected-note {{method 'release' declared here}}
64 - (NSUInteger)retainCount; // expected-note {{method 'retainCount' declared here}}
68 - (id)retain{return 0;} // expected-error {{ARC forbids implementation of 'retain'}}
69 - (id)autorelease{return 0;} // expected-error {{ARC forbids implementation of 'autorelease'}}
70 - (oneway void)release{} // expected-error {{ARC forbids implementation of 'release'}}
71 - (NSUInteger)retainCount{ return 0; } // expected-error {{ARC forbids implementation of 'retainCount'}}
74 @implementation I(CAT)
75 - (id)retain{return 0;} // expected-error {{ARC forbids implementation of 'retain'}} \
76 // expected-warning {{category is implementing a method which will also be implemented by its primary class}}
77 - (id)autorelease{return 0;} // expected-error {{ARC forbids implementation of 'autorelease'}} \
78 // expected-warning {{category is implementing a method which will also be implemented by its primary class}}
79 - (oneway void)release{} // expected-error {{ARC forbids implementation of 'release'}} \
80 // expected-warning {{category is implementing a method which will also be implemented by its primary class}}
81 - (NSUInteger)retainCount{ return 0; } // expected-error {{ARC forbids implementation of 'retainCount'}} \
82 // expected-warning {{category is implementing a method which will also be implemented by its primary class}}
89 - (id)initWithInt: (int) i;
90 - (id)myInit __attribute__((objc_method_family(init)));
91 - (id)myBadInit __attribute__((objc_method_family(12))); // expected-error {{'objc_method_family' attribute requires parameter 1 to be an identifier}}
96 B *o1 = [[B alloc] initWithInt:0];
98 [o2 initWithInt:0]; // expected-warning {{expression result unused}}
99 B *o3 = [[B alloc] myInit];
100 [[B alloc] myInit]; // expected-warning {{expression result unused}}
104 @interface rdar8925835
105 - (void)foo:(void (^)(unsigned captureCount, I * const capturedStrings[captureCount]))block;
109 extern void test5_helper(__autoreleasing id *);
112 // Okay because of magic temporaries.
115 __autoreleasing id *a = &x; // expected-error {{initializing '__autoreleasing id *' with an expression of type '__strong id *' changes retain/release properties of pointer}}
117 a = &x; // expected-error {{assigning '__strong id *' to '__autoreleasing id *' changes retain/release properties of pointer}}
119 extern void test5_helper2(id const *);
122 extern void test5_helper3(__weak id *); // expected-note {{passing argument to parameter here}}
123 test5_helper3(&x); // expected-error {{passing '__strong id *' to parameter of type '__weak id *' changes retain/release properties of pointer}}
126 // rdar://problem/8937869
127 void test6(unsigned cond) {
131 id x; // expected-note {{jump bypasses initialization of __strong variable}}
133 case 1: // expected-error {{cannot jump}}
137 void test6a(unsigned cond) {
141 __weak id x; // expected-note {{jump bypasses initialization of __weak variable}}
143 case 1: // expected-error {{cannot jump}}
150 extern void test7_helper(NSError **);
154 void test7_weak(void) {
155 extern void test7_helper(NSError **);
159 void test7_unsafe(void) {
160 extern void test7_helper(NSError **); // expected-note {{passing argument to parameter here}}
161 __unsafe_unretained NSError *err;
162 test7_helper(&err); // expected-error {{passing 'NSError *__unsafe_unretained *' to parameter of type 'NSError *__autoreleasing *' changes retain/release properties of pointer}}
165 @class Test8_incomplete;
166 @interface Test8_complete @end;
167 @interface Test8_super @end;
168 @interface Test8 : Test8_super
170 - (id) init01; // expected-note {{declaration in interface}} \
171 // expected-note{{overridden method}}
172 - (id) init02; // expected-note{{overridden method}}
173 - (id) init03; // covariance
174 - (id) init04; // covariance
175 - (id) init05; // expected-note{{overridden method}}
177 - (void) init10; // expected-note {{declaration in interface is not in the 'init' family because its result type is not an object pointer}}
180 - (void) init13; // expected-note {{declaration in interface is not in the 'init' family because its result type is not an object pointer}}
181 - (void) init14; // expected-note {{declaration in interface is not in the 'init' family because its result type is not an object pointer}}
184 // These should be invalid to actually call.
185 - (Test8_incomplete*) init20;
186 - (Test8_incomplete*) init21; // expected-note {{declaration in interface}}
187 - (Test8_incomplete*) init22;
188 - (Test8_incomplete*) init23;
189 - (Test8_incomplete*) init24;
190 - (Test8_incomplete*) init25;
192 - (Test8_super*) init30; // id exception to covariance
193 - (Test8_super*) init31; // expected-note {{declaration in interface}} \
194 // expected-note{{overridden method}}
195 - (Test8_super*) init32; // expected-note{{overridden method}}
196 - (Test8_super*) init33;
197 - (Test8_super*) init34; // covariance
198 - (Test8_super*) init35; // expected-note{{overridden method}}
200 - (Test8*) init40; // id exception to covariance
201 - (Test8*) init41; // expected-note {{declaration in interface}} \
202 // expected-note{{overridden method}}
203 - (Test8*) init42; // expected-note{{overridden method}}
204 - (Test8*) init43; // this should be a warning, but that's a general language thing, not an ARC thing
206 - (Test8*) init45; // expected-note{{overridden method}}
208 - (Test8_complete*) init50; // expected-error {{init methods must return a type related to the receiver type}}
209 - (Test8_complete*) init51; // expected-error {{init methods must return a type related to the receiver type}}
210 - (Test8_complete*) init52; // expected-error {{init methods must return a type related to the receiver type}}
211 - (Test8_complete*) init53; // expected-error {{init methods must return a type related to the receiver type}}
212 - (Test8_complete*) init54; // expected-error {{init methods must return a type related to the receiver type}}
213 - (Test8_complete*) init55; // expected-error {{init methods must return a type related to the receiver type}}
215 @implementation Test8
216 - (id) init00 { return 0; }
217 - (id) init10 { return 0; } // expected-error {{method implementation does not match its declaration}}
218 - (id) init20 { return 0; }
219 - (id) init30 { return 0; }
220 - (id) init40 { return 0; }
221 - (id) init50 { return 0; }
223 - (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}} \
224 // expected-warning{{method is expected to return an instance of its class type 'Test8', but is declared to return 'void'}}
226 - (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}}
227 - (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}} \
228 // expected-warning{{method is expected to return an instance of its class type 'Test8', but is declared to return 'void'}}
229 - (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}} \
230 // expected-warning{{method is expected to return an instance of its class type 'Test8', but is declared to return 'void'}}
233 - (Test8_incomplete*) init02 { return 0; } // expected-error {{init methods must return a type related to the receiver type}} \
234 // expected-warning{{method is expected to return an instance of its class type 'Test8', but is declared to return 'Test8_incomplete *'}}
235 - (Test8_incomplete*) init12 { return 0; } // expected-error {{init methods must return a type related to the receiver type}}
236 - (Test8_incomplete*) init22 { return 0; } // expected-error {{init methods must return a type related to the receiver type}}
237 - (Test8_incomplete*) init32 { return 0; } // expected-error {{init methods must return a type related to the receiver type}} \
238 // expected-warning{{method is expected to return an instance of its class type 'Test8', but is declared to return 'Test8_incomplete *'}}
239 - (Test8_incomplete*) init42 { return 0; } // expected-error {{init methods must return a type related to the receiver type}} \
240 // expected-warning{{method is expected to return an instance of its class type 'Test8', but is declared to return 'Test8_incomplete *'}}
241 - (Test8_incomplete*) init52 { return 0; } // expected-error {{init methods must return a type related to the receiver type}}
243 - (Test8_super*) init03 { return 0; }
244 - (Test8_super*) init13 { return 0; } // expected-error {{method implementation does not match its declaration}}
245 - (Test8_super*) init23 { return 0; }
246 - (Test8_super*) init33 { return 0; }
247 - (Test8_super*) init43 { return 0; }
248 - (Test8_super*) init53 { return 0; }
250 - (Test8*) init04 { return 0; }
251 - (Test8*) init14 { return 0; } // expected-error {{method implementation does not match its declaration}}
252 - (Test8*) init24 { return 0; }
253 - (Test8*) init34 { return 0; }
254 - (Test8*) init44 { return 0; }
255 - (Test8*) init54 { return 0; }
257 - (Test8_complete*) init05 { return 0; } // expected-error {{init methods must return a type related to the receiver type}} \
258 // expected-warning{{method is expected to return an instance of its class type 'Test8', but is declared to return 'Test8_complete *'}}
259 - (Test8_complete*) init15 { return 0; } // expected-error {{init methods must return a type related to the receiver type}}
260 - (Test8_complete*) init25 { return 0; } // expected-error {{init methods must return a type related to the receiver type}}
261 - (Test8_complete*) init35 { return 0; } // expected-error {{init methods must return a type related to the receiver type}} \
262 // expected-warning{{method is expected to return an instance of its class type 'Test8', but is declared to return 'Test8_complete *'}}
263 - (Test8_complete*) init45 { return 0; } // expected-error {{init methods must return a type related to the receiver type}} \
264 // expected-warning{{method is expected to return an instance of its class type 'Test8', but is declared to return 'Test8_complete *'}}
265 - (Test8_complete*) init55 { return 0; } // expected-error {{init methods must return a type related to the receiver type}}
268 @class Test9_incomplete;
270 - (Test9_incomplete*) init1; // expected-error {{init methods must return a type related to the receiver type}}
271 - (Test9_incomplete*) init2;
277 // Test that the inference rules are different for fast enumeration variables.
278 void test10(id collection) {
279 for (id x in collection) {
280 __strong id *ptr = &x; // expected-warning {{initializing '__strong id *' with an expression of type 'const __strong id *' discards qualifiers}}
283 for (__strong id x in collection) {
284 __weak id *ptr = &x; // expected-error {{initializing '__weak id *' with an expression of type '__strong id *' changes retain/release properties of pointer}}
288 // rdar://problem/9078626
289 #define nil ((void*) 0)
290 void test11(id op, void *vp) {
298 // FIXME: Shouldn't these be consistent?
299 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}}
303 void test12(id collection) {
304 for (id x in collection) {
305 x = 0; // expected-error {{fast enumeration variables cannot be modified in ARC by default; declare the variable __strong to allow this}}
308 for (const id x in collection) { // expected-note {{variable 'x' declared const here}}
309 x = 0; // expected-error {{cannot assign to variable 'x' with const-qualified type 'const __strong id'}}
312 for (__strong id x in collection) {
321 @implementation Test13
326 self = 0; // expected-error {{cannot assign to 'self' outside of a method in the init family}}
330 // <rdar://problem/10274056>
332 - (id) consumesSelf __attribute__((ns_consumes_self));
334 @implementation Test13_B
335 - (id) consumesSelf {
336 self = 0; // no-warning
340 // rdar://problem/9172151
341 @class Test14A, Test14B;
343 extern void test14_consume(id *);
344 extern int test14_cond(void);
345 extern float test14_nowriteback(id __autoreleasing const *); // expected-note{{passing argument to parameter here}}
351 id vla[test14_cond() + 10];
353 test14_consume((__strong id*) &a);
354 test14_consume((test14_cond() ? (__strong id*) &b : &i));
355 test14_consume(test14_cond() ? 0 : &a);
356 test14_consume(test14_cond() ? (void*) 0 : (&a));
357 test14_consume(cla); // expected-error {{passing address of non-scalar object to __autoreleasing parameter for write-back}}
358 test14_consume(vla); // expected-error {{passing address of non-scalar object to __autoreleasing parameter for write-back}}
359 test14_consume(&cla[5]); // expected-error {{passing address of non-scalar object to __autoreleasing parameter for write-back}}
361 __strong id *test14_indirect(void);
362 test14_consume(test14_indirect()); // expected-error {{passing address of non-local object to __autoreleasing parameter for write-back}}
364 extern id test14_global;
365 test14_consume(&test14_global); // expected-error {{passing address of non-local object to __autoreleasing parameter for write-back}}
367 extern __strong id *test14_global_ptr;
368 test14_consume(test14_global_ptr); // expected-error {{passing address of non-local object to __autoreleasing parameter for write-back}}
370 static id static_local;
371 test14_consume(&static_local); // expected-error {{passing address of non-local object to __autoreleasing parameter for write-back}}
374 test14_nowriteback(&static_local); // okay, not a write-back.
375 test14_nowriteback(wip); // expected-error{{passing '__weak id *' to parameter of type '__autoreleasing id const *' changes retain/release properties of pointer}}
379 __block __autoreleasing id x; // expected-error {{__block variables cannot have __autoreleasing ownership}}
384 - (void) test16_0: (int) x;
385 - (int) test16_1: (int) x; // expected-note {{one possibility}}
386 - (int) test16_2: (int) x; // expected-note {{one possibility}}
387 - (id) test16_3: (int) x __attribute__((ns_returns_retained)); // expected-note {{one possibility}}
388 - (void) test16_4: (int) x __attribute__((ns_consumes_self)); // expected-note {{one possibility}}
389 - (void) test16_5: (id) __attribute__((ns_consumed)) x; // expected-note {{one possibility}}
390 - (void) test16_6: (id) x;
394 - (void) test16_0: (int) x;
395 - (int) test16_1: (char*) x; // expected-note {{also found}}
396 - (char*) test16_2: (int) x; // expected-note {{also found}}
397 - (id) test16_3: (int) x; // expected-note {{also found}}
398 - (void) test16_4: (int) x; // expected-note {{also found}}
399 - (void) test16_5: (id) x; // expected-note {{also found}}
400 - (void) test16_6: (struct Test16 *) x;
406 [v test16_1: 0]; // expected-error {{multiple methods named 'test16_1:' found with mismatched result, parameter type or attributes}}
407 [v test16_2: 0]; // expected-error {{multiple methods named}}
408 [v test16_3: 0]; // expected-error {{multiple methods named}}
409 [v test16_4: 0]; // expected-error {{multiple methods named}}
410 [v test16_5: 0]; // expected-error {{multiple methods named}}
414 @class Test17; // expected-note 3{{forward declaration of class here}}
421 [v0 test17]; // expected-error {{receiver type 'Test17' for instance message is a forward declaration}}
424 [v1 test17]; // expected-error {{receiver type 'Test17<Test17p>' for instance message is a forward declaration}}
426 [Test17 test17]; // expected-error {{receiver 'Test17' for class message is a forward declaration}}
431 [x test18]; // expected-error {{instance method 'test18' not found ; did you mean 'test17'?}}
434 extern struct Test19 *test19a;
435 struct Test19 *const test19b = 0;
438 x = (id) test19a; // expected-error {{bridged cast}} \
439 // expected-note{{use __bridge to convert directly (no change in ownership)}} \
440 // expected-note{{use CFBridgingRelease call to transfer ownership of a +1 'struct Test19 *' into ARC}}
441 x = (id) test19b; // expected-error {{bridged cast}} \
442 // expected-note{{use __bridge to convert directly (no change in ownership)}} \
443 // expected-note{{use CFBridgingRelease call to transfer ownership of a +1 'struct Test19 *' into ARC}}
446 // rdar://problem/8951453
447 static __thread id test20_implicit; // expected-error {{thread-local variable has non-trivial ownership: type is '__strong id'}}
448 static __thread __strong id test20_strong; // expected-error {{thread-local variable has non-trivial ownership: type is '__strong id'}}
449 static __thread __weak id test20_weak; // expected-error {{thread-local variable has non-trivial ownership: type is '__weak id'}}
450 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}}
451 static __thread __unsafe_unretained id test20_unsafe;
453 static __thread id test20_implicit; // expected-error {{thread-local variable has non-trivial ownership: type is '__strong id'}}
454 static __thread __strong id test20_strong; // expected-error {{thread-local variable has non-trivial ownership: type is '__strong id'}}
455 static __thread __weak id test20_weak; // expected-error {{thread-local variable has non-trivial ownership: type is '__weak id'}}
456 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}}
457 static __thread __unsafe_unretained id test20_unsafe;
465 // Check casting w/ ownership qualifiers.
468 (void)(__weak id *)sip; // expected-error{{casting '__strong id *' to type '__weak id *' changes retain/release properties of pointer}}
469 (void)(__weak const id *)sip; // expected-error{{casting '__strong id *' to type '__weak id const *' changes retain/release properties of pointer}}
470 (void)(__autoreleasing id *)sip; // expected-error{{casting '__strong id *' to type '__autoreleasing id *' changes retain/release properties of pointer}}
471 (void)(__autoreleasing const id *)sip; // okay
474 // rdar://problem/9340462
475 void test22(id x[]) { // expected-error {{must explicitly describe intended ownership of an object array parameter}}
478 // rdar://problem/9400219
482 ptr = (ptr ? @"foo" : 0);
483 ptr = (ptr ? @"foo" : @"bar");
487 extern void test24_helper(void);
488 return test24_helper(), (void*) 0;
493 @property (assign) id content;
496 @interface Foo : Base
506 // <rdar://problem/9398437>
507 void test25(Class *classes) {
508 Class *other_classes;
509 test25(other_classes);
513 extern id test26_var1;
514 __sync_swap(&test26_var1, 0, y); // expected-error {{cannot perform atomic operation on a pointer to type '__strong id': type has non-trivial ownership}}
516 extern __unsafe_unretained id test26_var2;
517 __sync_swap(&test26_var2, 0, y);
522 - (id) initWithInt: (int) x;
524 @implementation Test26
525 - (id) init { return self; }
526 - (id) initWithInt: (int) x {
527 [self init]; // expected-error {{the result of a delegate init call must be immediately returned or assigned to 'self'}}
538 @property (readonly) id ro;
539 @property (readonly) id custom_ro;
542 @property (readonly) __weak id myProp1;
543 @property (readonly) id myProp2;
544 @property (readonly) __strong id myProp3;
547 @implementation Test27
552 @synthesize myProp1 = _myProp1;
556 -(id)custom_ro { return 0; }
561 @property (nonatomic, assign) __strong id a; // expected-error {{unsafe_unretained property 'a' may not also be declared __strong}}
565 @property (nonatomic, assign) __strong id b; // expected-error {{unsafe_unretained property 'b' may not also be declared __strong}}
568 @implementation Test28
574 typedef struct Bark Bark;
579 @implementation Test29
593 @implementation Test30
594 + (id) new { return 0; }
596 __weak id x = [Test30 new]; // expected-warning {{assigning retained object to weak variable}}
597 id __unsafe_unretained u = [Test30 new]; // expected-warning {{assigning retained object to unsafe_unretained variable}}
599 x = [Test30 new]; // expected-warning {{assigning retained object to weak variable}}
600 u = [Test30 new]; // expected-warning {{assigning retained object to unsafe_unretained variable}}
606 @protocol PTest31 @end
614 int i = (ids->isa ? 1 : 0); // expected-error {{member reference base type 'id' is not a structure or union}}
615 int j = (pids->isa ? 1 : 0); // expected-error {{member reference base type 'id<PTest31>' is not a structure or union}}
616 int k = (pcls->isa ? i : j); // expected-error {{member reference base type 'Class<PTest31>' is not a structure or union}}
617 return cls->isa ? i : j; // expected-error {{member reference base type 'Class' is not a structure or union}}
627 id Test32(__weak ITest32 *x) {
629 x->ivar = 0; // expected-error {{dereferencing a __weak pointer is not allowed}}
630 return y ? y->ivar // expected-error {{dereferencing a __weak pointer is not allowed}}
631 : (*x).ivar; // expected-error {{dereferencing a __weak pointer is not allowed}}
635 extern int printf(const char*, ...);
636 typedef long intptr_t;
638 int Test33(id someid) {
639 printf( "Hello%ld", (intptr_t)someid);
645 @property (nonatomic, retain) id newName __attribute__((ns_returns_not_retained)) ;
647 @property (nonatomic, retain) id newName1 __attribute__((ns_returns_not_retained)) ;
648 - (id) newName1 __attribute__((ns_returns_not_retained));
650 @property (nonatomic, retain) id newName2 __attribute__((ns_returns_not_retained)); // expected-note {{roperty declared here}}
651 - (id) newName2; // expected-warning {{property declared as returning non-retained objects; getter returning retained objects}}
657 @synthesize newName1;
658 - (id) newName1 { return 0; }
660 @synthesize newName2;
664 extern void test36_helper(id*);
669 test36_helper(xp); // expected-error {{passing address of non-local object to __autoreleasing parameter for write-back}}
671 // rdar://problem/9665710
674 ^{ test36_helper(&y); }();
676 __strong int non_objc_type; // expected-warning {{'__strong' only applies to Objective-C object or block pointer types}}
679 void test36(int first, ...) {
680 // <rdar://problem/9758798>
681 __builtin_va_list arglist;
682 __builtin_va_start(arglist, first);
683 id obj = __builtin_va_arg(arglist, id);
684 __builtin_va_end(arglist);
687 @class Test37; // expected-note{{forward declaration of class here}}
688 void test37(Test37 *c) {
689 for (id y in c) { // expected-error {{collection expression type 'Test37' is a forward declaration}}
693 (void)sizeof(id*); // no error.
696 // rdar://problem/9887979
701 extern Test38 *test38_helper(void);
702 switch (test38_helper().value) {
711 void _NSCalc(NSColor* color, NSColor* bezelColors[]) __attribute__((unavailable("not available in automatic reference counting mode")));
713 void _NSCalcBeze(NSColor* color, NSColor* bezelColors[]); // expected-error {{must explicitly describe intended ownership of an object array parameter}}
716 @interface RestaurantTableViewCell
717 - (void) restaurantLocation;
720 @interface Radar9970739
724 @implementation Radar9970739
726 RestaurantTableViewCell *cell;
727 [cell restaurantLocatoin]; // expected-error {{no visible @interface for 'RestaurantTableViewCell' declares the selector 'restaurantLocatoin'}}
732 @interface Radar11814185
733 @property (nonatomic, weak) Radar11814185* picker1;
738 @implementation Radar11814185
744 picker1 = [[Radar11814185 alloc] init]; // expected-warning {{assigning retained object to weak variable; object will be released after assignment}}
745 self.picker1 = [[Radar11814185 alloc] init]; // expected-warning {{assigning retained object to weak property; object will be released after assignment}}
748 + alloc { return 0; }
752 // <rdar://problem/12569201>. Warn on cases of initializing a weak variable
753 // with an Objective-C object literal.
754 void rdar12569201(id key, id value) {
756 __weak id x = @"foo"; // no-warning
757 __weak id y = @{ key : value }; // expected-warning {{assigning dictionary literal to a weak variable; object will be released after assignment}}
758 __weak id z = @[ value ]; // expected-warning {{assigning array literal to a weak variable; object will be released after assignment}}
759 __weak id b = ^() {}; // expected-warning {{assigning block literal to a weak variable; object will be released after assignment}}
760 __weak id n = @42; // expected-warning {{assigning numeric literal to a weak variable; object will be released after assignment}}
761 __weak id e = @(42); // expected-warning {{assigning numeric literal to a weak variable; object will be released after assignment}}
762 __weak id m = @(41 + 1); // expected-warning {{assigning boxed expression to a weak variable; object will be released after assignment}}
765 y = @{ key : value }; // expected-warning {{assigning dictionary literal to a weak variable; object will be released after assignment}}
766 z = @[ value ]; // expected-warning {{assigning array literal to a weak variable; object will be released after assignment}}
767 b = ^() {}; // expected-warning {{assigning block literal to a weak variable; object will be released after assignment}}
768 n = @42; // expected-warning {{assigning numeric literal to a weak variable; object will be released after assignment}}
769 e = @(42); // expected-warning {{assigning numeric literal to a weak variable; object will be released after assignment}}
770 m = @(41 + 1); // expected-warning {{assigning boxed expression to a weak variable; object will be released after assignment}}
774 - (void)method:(id[])objects; // expected-error{{must explicitly describe intended ownership of an object array parameter}}
778 @interface NSMutableArray : NSArray @end
780 typedef __strong NSMutableArray * PSNS;
782 void test(NSArray *x) {
783 NSMutableArray *y = x; // expected-warning {{incompatible pointer types initializing 'NSMutableArray *' with an expression of type 'NSArray *'}}
784 __strong NSMutableArray *y1 = x; // expected-warning {{incompatible pointer types initializing 'NSMutableArray *' with an expression of type 'NSArray *'}}
785 PSNS y2 = x; // expected-warning {{incompatible pointer types initializing 'NSMutableArray *' with an expression of type 'NSArray *'}}
791 void foo(NSArray *array) {
792 for (NSString *string in array) {
793 for (string in @[@"blah", @"more blah", string]) { // expected-error {{selector element of type 'NSString *const __strong' cannot be a constant l-value}}
800 #define TKAssertEqual(a, b) do{\
801 __typeof(a) a_res = (a);\
802 __typeof(b) b_res = (b);\
803 if ((a_res) != (b_res)) {\
810 TKAssertEqual(object, nil);
811 TKAssertEqual(object, (id)nil);
814 void block_capture_autoreleasing(A * __autoreleasing *a,
815 A **b, // expected-note {{declare the parameter __strong or capture a __block __strong variable to keep values alive across autorelease pools}}
816 A * _Nullable *c, // expected-note {{declare the parameter __strong or capture a __block __strong variable to keep values alive across autorelease pools}}
817 A * _Nullable __autoreleasing *d,
818 A ** _Nullable e, // expected-note {{declare the parameter __strong or capture a __block __strong variable to keep values alive across autorelease pools}}
819 A * __autoreleasing * _Nullable f,
820 id __autoreleasing *g,
821 id *h, // expected-note {{declare the parameter __strong or capture a __block __strong variable to keep values alive across autorelease pools}}
822 id _Nullable *i, // expected-note {{declare the parameter __strong or capture a __block __strong variable to keep values alive across autorelease pools}}
823 id _Nullable __autoreleasing *j,
824 id * _Nullable k, // expected-note {{declare the parameter __strong or capture a __block __strong variable to keep values alive across autorelease pools}}
825 id __autoreleasing * _Nullable l) {
828 (void)*b; // expected-warning {{block captures an autoreleasing out-parameter, which may result in use-after-free bugs}}
829 (void)*c; // expected-warning {{block captures an autoreleasing out-parameter, which may result in use-after-free bugs}}
831 (void)*e; // expected-warning {{block captures an autoreleasing out-parameter, which may result in use-after-free bugs}}
834 (void)*h; // expected-warning {{block captures an autoreleasing out-parameter, which may result in use-after-free bugs}}
835 (void)*i; // expected-warning {{block captures an autoreleasing out-parameter, which may result in use-after-free bugs}}
837 (void)*k; // expected-warning {{block captures an autoreleasing out-parameter, which may result in use-after-free bugs}}