blob: d47428d1d60729e4435e51655b62bb953e4efcba [file] [log] [blame]
Fariborz Jahanian918546c2012-08-30 23:56:02 +00001// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fsyntax-only -fobjc-arc -fblocks -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 -Wexplicit-ownership-type -verify -Wno-objc-root-class %s
Fariborz Jahanian6d09f012011-10-28 20:06:07 +00003// 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 =
Fariborz Jahanian56892c12011-10-31 17:27:06 +000020 (__bridge CFStringRef) (__strong NSString *)CFBridgingRelease(); // expected-error {{explicit ownership qualifier on cast result has no effect}}
Fariborz Jahanian6d09f012011-10-28 20:06:07 +000021
22 myString =
Fariborz Jahanian56892c12011-10-31 17:27:06 +000023 (__bridge CFStringRef) (__autoreleasing PNSString) CFBridgingRelease(); // expected-error {{explicit ownership qualifier on cast result has no effect}}
Fariborz Jahanian6d09f012011-10-28 20:06:07 +000024 myString =
25 (__bridge CFStringRef) (AUTORELEASEPNSString) CFBridgingRelease(); // OK
Fariborz Jahanianfc2eff52011-10-29 00:06:10 +000026 myString =
Fariborz Jahanian56892c12011-10-31 17:27:06 +000027 (__bridge CFStringRef) (typeof(__strong NSString *)) CFBridgingRelease(); // expected-error {{explicit ownership qualifier on cast result has no effect}}
Fariborz Jahanian6d09f012011-10-28 20:06:07 +000028 return myString;
29}
30
31- (void)decodeValueOfObjCType:(const char *)type at:(void *)addr {
32 __autoreleasing id *stuff = (__autoreleasing id *)addr;
33}
34@end
John McCalld85bf9d2012-02-08 00:46:41 +000035
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;
Fariborz Jahanian918546c2012-08-30 23:56:02 +000043
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