xref: /minix3/external/bsd/llvm/dist/clang/test/SemaObjCXX/arc-objc-lifetime.mm (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc// 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
2*f4a2713aSLionel Sambuc// rdar://10244607
3*f4a2713aSLionel Sambuc
4*f4a2713aSLionel Sambuctypedef const struct __CFString * CFStringRef;
5*f4a2713aSLionel Sambuc@class NSString;
6*f4a2713aSLionel Sambuc
7*f4a2713aSLionel SambucNSString *CFBridgingRelease();
8*f4a2713aSLionel Sambuc
9*f4a2713aSLionel Sambuctypedef NSString * PNSString;
10*f4a2713aSLionel Sambuc
11*f4a2713aSLionel Sambuctypedef __autoreleasing NSString * AUTORELEASEPNSString;
12*f4a2713aSLionel Sambuc
13*f4a2713aSLionel Sambuc@interface I @end
14*f4a2713aSLionel Sambuc
15*f4a2713aSLionel Sambuc@implementation I
16*f4a2713aSLionel Sambuc- (CFStringRef)myString
17*f4a2713aSLionel Sambuc{
18*f4a2713aSLionel Sambuc    CFStringRef myString =
19*f4a2713aSLionel Sambuc      (__bridge CFStringRef) (__strong NSString *)CFBridgingRelease(); // expected-error {{explicit ownership qualifier on cast result has no effect}}
20*f4a2713aSLionel Sambuc
21*f4a2713aSLionel Sambuc    myString =
22*f4a2713aSLionel Sambuc      (__bridge CFStringRef) (__autoreleasing PNSString) CFBridgingRelease(); // expected-error {{explicit ownership qualifier on cast result has no effect}}
23*f4a2713aSLionel Sambuc    myString =
24*f4a2713aSLionel Sambuc      (__bridge CFStringRef) (AUTORELEASEPNSString) CFBridgingRelease(); // OK
25*f4a2713aSLionel Sambuc    myString =
26*f4a2713aSLionel Sambuc      (__bridge CFStringRef) (typeof(__strong NSString *)) CFBridgingRelease(); // expected-error {{explicit ownership qualifier on cast result has no effect}}
27*f4a2713aSLionel Sambuc    return myString;
28*f4a2713aSLionel Sambuc}
29*f4a2713aSLionel Sambuc
30*f4a2713aSLionel Sambuc- (void)decodeValueOfObjCType:(const char *)type at:(void *)addr {
31*f4a2713aSLionel Sambuc        __autoreleasing id *stuff = (__autoreleasing id *)addr;
32*f4a2713aSLionel Sambuc}
33*f4a2713aSLionel Sambuc@end
34*f4a2713aSLionel Sambuc
35*f4a2713aSLionel Sambuc// rdar://problem/10711456
36*f4a2713aSLionel Sambuc__strong I *__strong test1; // expected-error {{the type 'I *__strong' is already explicitly ownership-qualified}}
37*f4a2713aSLionel Sambuc__strong I *(__strong test2); // expected-error {{the type 'I *__strong' is already explicitly ownership-qualified}}
38*f4a2713aSLionel Sambuc__strong I *(__strong (test3)); // expected-error {{the type 'I *__strong' is already explicitly ownership-qualified}}
39*f4a2713aSLionel Sambuc__unsafe_unretained __typeof__(test3) test4;
40*f4a2713aSLionel Sambuctypedef __strong I *strong_I;
41*f4a2713aSLionel Sambuc__unsafe_unretained strong_I test5;
42*f4a2713aSLionel Sambuc
43*f4a2713aSLionel Sambuc// rdar://10907090
44*f4a2713aSLionel Sambuctypedef void (^T) ();
45*f4a2713aSLionel Sambuc@interface NSObject @end
46*f4a2713aSLionel Sambuc@protocol P;
47*f4a2713aSLionel Sambuc@interface Radar10907090 @end
48*f4a2713aSLionel Sambuc
49*f4a2713aSLionel Sambuc@implementation Radar10907090
50*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}} \
51*f4a2713aSLionel Sambuc					// expected-warning {{method parameter of type '__autoreleasing id<P> &' with no explicit ownership}}
52*f4a2713aSLionel Sambuc- (void) MM : (NSObject*) arg0 : (__strong NSObject**)arg : (id) arg1 : (__strong id*) arg2 {}
53*f4a2713aSLionel Sambuc- (void) M : (NSObject**)arg0 : (id*)arg {} // expected-warning {{method parameter of type 'NSObject *__autoreleasing *' with no explicit ownership}} \
54*f4a2713aSLionel Sambuc                                            // expected-warning {{method parameter of type '__autoreleasing id *' with no explicit ownership}}
55*f4a2713aSLionel Sambuc- (void) N : (__strong NSObject***) arg0 : (__strong NSObject<P>***)arg : (float**) arg1 : (double) arg2 {}
56*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}}
57*f4a2713aSLionel Sambuc@end
58*f4a2713aSLionel Sambuc
59*f4a2713aSLionel Sambuc// rdar://12280826
60*f4a2713aSLionel Sambuc@class NSMutableDictionary, NSError;
61*f4a2713aSLionel Sambuc@interface Radar12280826
62*f4a2713aSLionel Sambuc- (void)createInferiorTransportAndSetEnvironment:(NSMutableDictionary*)environment error:(__autoreleasing NSError*&)error;
63*f4a2713aSLionel Sambuc@end
64*f4a2713aSLionel Sambuc
65*f4a2713aSLionel Sambuc@implementation Radar12280826
66*f4a2713aSLionel Sambuc- (void)createInferiorTransportAndSetEnvironment:(NSMutableDictionary*)environment error:(__autoreleasing NSError*&)error {}
67*f4a2713aSLionel Sambuc@end
68*f4a2713aSLionel Sambuc
69