1// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fsyntax-only -fobjc-arc -fblocks -fobjc-runtime-has-weak -Wexplicit-ownership-type -verify -Wno-objc-root-class %s 2// RUN: %clang_cc1 -x objective-c++ -triple x86_64-apple-darwin11 -fsyntax-only -fobjc-arc -fblocks -fobjc-runtime-has-weak -Wexplicit-ownership-type -verify -Wno-objc-root-class %s 3// rdar://10244607 4 5typedef const struct __CFString * CFStringRef; 6@class NSString; 7 8NSString *CFBridgingRelease(); 9 10typedef NSString * PNSString; 11 12typedef __autoreleasing NSString * AUTORELEASEPNSString; 13 14@interface I @end 15 16@implementation I 17- (CFStringRef)myString 18{ 19 CFStringRef myString = 20 (__bridge CFStringRef) (__strong NSString *)CFBridgingRelease(); // expected-error {{explicit ownership qualifier on cast result has no effect}} 21 22 myString = 23 (__bridge CFStringRef) (__autoreleasing PNSString) CFBridgingRelease(); // expected-error {{explicit ownership qualifier on cast result has no effect}} 24 myString = 25 (__bridge CFStringRef) (AUTORELEASEPNSString) CFBridgingRelease(); // OK 26 myString = 27 (__bridge CFStringRef) (typeof(__strong NSString *)) CFBridgingRelease(); // expected-error {{explicit ownership qualifier on cast result has no effect}} 28 return myString; 29} 30 31- (void)decodeValueOfObjCType:(const char *)type at:(void *)addr { 32 __autoreleasing id *stuff = (__autoreleasing id *)addr; 33} 34@end 35 36// rdar://problem/10711456 37__strong I *__strong test1; // expected-error {{the type 'I *__strong' is already explicitly ownership-qualified}} 38__strong I *(__strong test2); // expected-error {{the type 'I *__strong' is already explicitly ownership-qualified}} 39__strong I *(__strong (test3)); // expected-error {{the type 'I *__strong' is already explicitly ownership-qualified}} 40__unsafe_unretained __typeof__(test3) test4; 41typedef __strong I *strong_I; 42__unsafe_unretained strong_I test5; 43 44// rdar://10907090 45typedef void (^T) (); 46@interface NSObject @end 47@protocol P; 48@interface Radar10907090 @end 49 50@implementation Radar10907090 51- (void) MMM : (NSObject*) arg0 : (NSObject<P>**)arg : (id) arg1 : (id<P>*) arg2 {} // expected-warning {{method parameter of type 'NSObject<P> *__autoreleasing *' with no explicit ownership}} \ 52 // expected-warning {{method parameter of type '__autoreleasing id<P> *' with no explicit ownership}} 53- (void) MM : (NSObject*) arg0 : (__strong NSObject**)arg : (id) arg1 : (__strong id*) arg2 {} 54- (void) M : (NSObject**)arg0 : (id*)arg {} // expected-warning {{method parameter of type 'NSObject *__autoreleasing *' with no explicit ownership}} \ 55 // expected-warning {{method parameter of type '__autoreleasing id *' with no explicit ownership}} 56- (void) N : (__strong NSObject***) arg0 : (__strong NSObject<P>***)arg : (float**) arg1 : (double) arg2 {} 57- (void) BLOCK : (T*) arg0 : (T)arg : (__strong T*) arg1 {} // expected-warning {{method parameter of type '__autoreleasing T *' (aka 'void (^__autoreleasing *)()') with no explicit ownership}} 58@end 59 60// rdar://12280826 61@class NSMutableDictionary, NSError; 62@interface Radar12280826 63- (void)createInferiorTransportAndSetEnvironment:(NSMutableDictionary*)environment error:(__autoreleasing NSError**)error; 64@end 65 66@implementation Radar12280826 67- (void)createInferiorTransportAndSetEnvironment:(NSMutableDictionary*)environment error:(__autoreleasing NSError**)error {} 68@end 69 70// <rdar://problem/12367446> 71typedef __strong id strong_id; 72typedef NSObject *NSObject_ptr; 73typedef __strong NSObject *strong_NSObject_ptr; 74 75// Warn 76__strong id f1(); // expected-warning{{ARC __strong lifetime qualifier on return type is ignored}} 77NSObject __unsafe_unretained *f2(int); // expected-warning{{ARC __unsafe_unretained lifetime qualifier on return type is ignored}} 78__autoreleasing NSObject *f3(void); // expected-warning{{ARC __autoreleasing lifetime qualifier on return type is ignored}} 79NSObject * __strong f4(void); // expected-warning{{ARC __strong lifetime qualifier on return type is ignored}} 80NSObject_ptr __strong f5(); // expected-warning{{ARC __strong lifetime qualifier on return type is ignored}} 81 82typedef __strong id (*fptr)(int); // expected-warning{{ARC __strong lifetime qualifier on return type is ignored}} 83 84// Don't warn 85strong_id f6(); 86strong_NSObject_ptr f7(); 87typedef __strong id (^block_ptr)(int); 88 89// rdar://10127067 90void test8_a() { 91 __weak id *(^myBlock)(void); 92 __weak id *var = myBlock(); 93 (void) (__strong id *) &myBlock; 94 (void) (__weak id *) &myBlock; // expected-error {{cast}} 95} 96void test8_b() { 97 __weak id (^myBlock)(void); 98 (void) (__weak id *) &myBlock; 99 (void) (__strong id *) &myBlock; // expected-error {{cast}} 100} 101void test8_c() { 102 __weak id (^*(^myBlock)(void))(void); 103 (void) (__weak id*) myBlock(); 104 (void) (__strong id*) myBlock(); // expected-error {{cast}} 105 (void) (__weak id*) &myBlock; // expected-error {{cast}} 106 (void) (__strong id*) &myBlock; 107} 108 109@class Test9; 110void test9_a() { 111 __weak Test9 **(^myBlock)(void); 112 __weak Test9 **var = myBlock(); 113 (void) (__strong Test9 **) &myBlock; 114 (void) (__weak Test9 **) &myBlock; // expected-error {{cast}} 115} 116void test9_b() { 117 __weak Test9 *(^myBlock)(void); 118 (void) (__weak Test9**) &myBlock; 119 (void) (__strong Test9**) &myBlock; // expected-error {{cast}} 120} 121void test9_c() { 122 __weak Test9 *(^*(^myBlock)(void))(void); 123 (void) (__weak Test9 **) myBlock(); 124 (void) (__strong Test9 **) myBlock(); // expected-error {{cast}} 125 (void) (__weak Test9 **) &myBlock; // expected-error {{cast}} 126 (void) (__strong Test9 **) &myBlock; 127} 128