1 // RUN: %clang_cc1 -fsyntax-only -fobjc-arc -fobjc-runtime-has-weak -verify -fblocks -Wno-incompatible-pointer-types %s
3 typedef const void * CFTypeRef;
4 CFTypeRef CFBridgingRetain(id X);
5 id CFBridgingRelease(CFTypeRef);
10 (void)(int*)arg; // expected-error {{cast of an Objective-C pointer to 'int *' is disallowed with ARC}}
12 (void)(__autoreleasing id*)arg; // expected-error {{cast of an Objective-C pointer to '__autoreleasing id *' is disallowed with ARC}}
13 (void)(id*)arg; // expected-error {{cast of an Objective-C pointer to '__strong id *' is disallowed with ARC}}
15 (void)(__autoreleasing id**)voidp_val;
16 (void)(void*)voidp_val;
17 (void)(void**)arg; // expected-error {{cast of an Objective-C pointer to 'void **' is disallowed with ARC}}
18 cvt((void*)arg); // expected-error {{cast of Objective-C pointer type 'id' to C pointer type 'void *' requires a bridged cast}} \
19 // expected-error {{implicit conversion of C pointer type 'void *' to Objective-C pointer type 'id' requires a bridged cast}} \
20 // expected-note 2 {{use __bridge to convert directly (no change in ownership)}} \
21 // expected-note {{use CFBridgingRetain call to make an ARC object available as a +1 'void *'}} \
22 // expected-note {{use CFBridgingRelease call to transfer ownership of a +1 'void *' into ARC}}
24 (void)(__strong id**)(0);
25 return arg; // expected-error {{implicit conversion of Objective-C pointer type 'id' to C pointer type 'void *' requires a bridged cast}} \
26 // expected-note {{use __bridge to convert directly (no change in ownership)}} \
27 // expected-note {{use CFBridgingRetain call to make an ARC object available as a +1 'void *'}}
30 void to_void(__strong id *sip, __weak id *wip,
31 __autoreleasing id *aip,
32 __unsafe_unretained id *uip) {
47 void from_void(void *vp) {
48 __strong id *sip = (__strong id *)vp;
49 __weak id *wip = (__weak id *)vp;
50 __autoreleasing id *aip = (__autoreleasing id *)vp;
51 __unsafe_unretained id *uip = (__unsafe_unretained id *)vp;
53 __strong id **sipp = (__strong id **)vp;
54 __weak id **wipp = (__weak id **)vp;
55 __autoreleasing id **aipp = (__autoreleasing id **)vp;
56 __unsafe_unretained id **uipp = (__unsafe_unretained id **)vp;
58 sip = vp; // expected-error{{implicit conversion of a non-Objective-C pointer type 'void *' to '__strong id *' is disallowed with ARC}}
59 wip = vp; // expected-error{{implicit conversion of a non-Objective-C pointer type 'void *' to '__weak id *' is disallowed with ARC}}
60 aip = vp; // expected-error{{implicit conversion of a non-Objective-C pointer type 'void *' to '__autoreleasing id *' is disallowed with ARC}}
61 uip = vp; // expected-error{{implicit conversion of a non-Objective-C pointer type 'void *' to '__unsafe_unretained id *' is disallowed with ARC}}
64 typedef void (^Block)(void);
65 typedef void (^Block_strong)(void) __strong;
66 typedef void (^Block_autoreleasing)(void) __autoreleasing;
70 void ownership_transfer_in_cast(void *vp, Block *pblk) {
71 __strong NSString **sip = (NSString**)(__strong id *)vp;
72 __weak NSString **wip = (NSString**)(__weak id *)vp;
73 __autoreleasing id *aip = (id*)(__autoreleasing id *)vp;
74 __unsafe_unretained id *uip = (id*)(__unsafe_unretained id *)vp;
76 __strong id **sipp = (id**)(__strong id **)vp;
77 __weak id **wipp = (id**)(__weak id **)vp;
78 __autoreleasing id **aipp = (id**)(__autoreleasing id **)vp;
79 __unsafe_unretained id **uipp = (id**)(__unsafe_unretained id **)vp;
81 Block_strong blk_strong1;
82 Block_strong blk_strong2 = (Block)blk_strong1;
83 Block_autoreleasing *blk_auto = (Block*)pblk;
86 (void)(id)&lv; // expected-error {{cast of an indirect pointer to an Objective-C pointer to 'id'}}
87 (void)(id*)lv; // expected-error {{cast of an Objective-C pointer to '__strong id *'}}
88 (void)(NSString*)&lv; // expected-error {{cast of an indirect pointer to an Objective-C pointer to 'NSString *'}}
89 (void)(NSString**)lv; // expected-error {{cast of an Objective-C pointer to 'NSString *__strong *'}}
90 (void)(Block)&lv; // expected-error {{cast of an indirect pointer to an Objective-C pointer to 'Block'}}
91 (void)(Block*)lv; // expected-error {{cast of an Objective-C pointer to '__strong Block *'}}
94 void conversion_in_conditional(id a, void* b) {
95 id c = 1 ? a : b; // expected-error {{operands to conditional of types 'id' and 'void *' are incompatible in ARC mode}}
96 id d = 1 ? b : a; // expected-error {{operands to conditional of types 'void *' and 'id' are incompatible in ARC mode}}
99 void conversion_pointer_to_id(__strong id *x) {
104 x = (__strong id *)&s;
105 x = &s; // expected-error {{implicit conversion of a non-Objective-C pointer type 'struct S *' to '__strong id *' is disallowed with ARC}}
107 p = x; // expected-error {{implicit conversion of an indirect pointer to an Objective-C pointer to 'struct S *' is disallowed with ARC}}