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