1 // RUN: %clang_cc1 -fsyntax-only -fobjc-arc -fobjc-runtime-has-weak -verify -fblocks %s 2 3 void * cvt(id arg) 4 { 5 void* voidp_val; 6 (void)(int*)arg; // expected-error {{cast of an Objective-C pointer to 'int *' is disallowed with ARC}} 7 (void)(id)arg; 8 (void)(__autoreleasing id*)arg; // expected-error {{cast of an Objective-C pointer to '__autoreleasing id *' is disallowed with ARC}} 9 (void)(id*)arg; // expected-error {{cast of an Objective-C pointer to '__strong id *' is disallowed with ARC}} 10 11 (void)(__autoreleasing id**)voidp_val; 12 (void)(void*)voidp_val; 13 (void)(void**)arg; // expected-error {{cast of an Objective-C pointer to 'void **' is disallowed with ARC}} 14 cvt((void*)arg); // expected-error {{cast of Objective-C pointer type 'id' to C pointer type 'void *' requires a bridged cast}} \ 15 // expected-error {{implicit conversion of C pointer type 'void *' to Objective-C pointer type 'id' requires a bridged cast}} \ 16 // expected-note 2 {{use __bridge to convert directly (no change in ownership)}} \ 17 // expected-note {{use __bridge_retained to make an ARC object available as a +1 'void *'}} \ 18 // expected-note {{use __bridge_transfer to transfer ownership of a +1 'void *' into ARC}} 19 cvt(0); 20 (void)(__strong id**)(0); 21 return arg; // expected-error {{implicit conversion of Objective-C pointer type 'id' to C pointer type 'void *' requires a bridged cast}} \ 22 // expected-note {{use __bridge to convert directly (no change in ownership)}} \ 23 // expected-note {{use __bridge_retained to make an ARC object available as a +1 'void *'}} 24 } 25 26 void to_void(__strong id *sip, __weak id *wip, 27 __autoreleasing id *aip, 28 __unsafe_unretained id *uip) { 29 void *vp1 = sip; 30 void *vp2 = wip; 31 void *vp3 = aip; 32 void *vp4 = uip; 33 (void)(void*)sip; 34 (void)(void*)wip; 35 (void)(void*)aip; 36 (void)(void*)uip; 37 (void)(void*)&sip; 38 (void)(void*)&wip; 39 (void)(void*)&aip; 40 (void)(void*)&uip; 41 } 42 43 void from_void(void *vp) { 44 __strong id *sip = (__strong id *)vp; 45 __weak id *wip = (__weak id *)vp; 46 __autoreleasing id *aip = (__autoreleasing id *)vp; 47 __unsafe_unretained id *uip = (__unsafe_unretained id *)vp; 48 49 __strong id **sipp = (__strong id **)vp; 50 __weak id **wipp = (__weak id **)vp; 51 __autoreleasing id **aipp = (__autoreleasing id **)vp; 52 __unsafe_unretained id **uipp = (__unsafe_unretained id **)vp; 53 54 sip = vp; // expected-error{{implicit conversion of a non-Objective-C pointer type 'void *' to '__strong id *' is disallowed with ARC}} 55 wip = vp; // expected-error{{implicit conversion of a non-Objective-C pointer type 'void *' to '__weak id *' is disallowed with ARC}} 56 aip = vp; // expected-error{{implicit conversion of a non-Objective-C pointer type 'void *' to '__autoreleasing id *' is disallowed with ARC}} 57 uip = vp; // expected-error{{implicit conversion of a non-Objective-C pointer type 'void *' to '__unsafe_unretained id *' is disallowed with ARC}} 58 } 59 60 typedef void (^Block)(); 61 typedef void (^Block_strong)() __strong; 62 typedef void (^Block_autoreleasing)() __autoreleasing; 63 64 @class NSString; 65 66 void ownership_transfer_in_cast(void *vp, Block *pblk) { 67 __strong NSString **sip = (NSString**)(__strong id *)vp; 68 __weak NSString **wip = (NSString**)(__weak id *)vp; 69 __autoreleasing id *aip = (id*)(__autoreleasing id *)vp; 70 __unsafe_unretained id *uip = (id*)(__unsafe_unretained id *)vp; 71 72 __strong id **sipp = (id**)(__strong id **)vp; 73 __weak id **wipp = (id**)(__weak id **)vp; 74 __autoreleasing id **aipp = (id**)(__autoreleasing id **)vp; 75 __unsafe_unretained id **uipp = (id**)(__unsafe_unretained id **)vp; 76 77 Block_strong blk_strong1; 78 Block_strong blk_strong2 = (Block)blk_strong1; 79 Block_autoreleasing *blk_auto = (Block*)pblk; 80 } 81