]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/SemaObjC/arc-type-conversion.m
Vendor import of clang release_30 branch r142614:
[FreeBSD/FreeBSD.git] / test / SemaObjC / arc-type-conversion.m
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 a non-Objective-C pointer type 'void *' to 'id' is disallowed with ARC}} \
16                    // expected-note{{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   cvt(0);
19   (void)(__strong id**)(0);
20   return arg; // expected-error {{implicit conversion of an Objective-C pointer to 'void *' is disallowed with ARC}}
21 }
22
23 void to_void(__strong id *sip, __weak id *wip,
24              __autoreleasing id *aip,
25              __unsafe_unretained id *uip) {
26   void *vp1 = sip;
27   void *vp2 = wip;
28   void *vp3 = aip;
29   void *vp4 = uip;
30   (void)(void*)sip;
31   (void)(void*)wip;
32   (void)(void*)aip;
33   (void)(void*)uip;
34   (void)(void*)&sip;
35   (void)(void*)&wip;
36   (void)(void*)&aip;
37   (void)(void*)&uip;
38 }
39
40 void from_void(void *vp) {
41   __strong id *sip = (__strong id *)vp;
42   __weak id *wip = (__weak id *)vp;
43   __autoreleasing id *aip = (__autoreleasing id *)vp;
44   __unsafe_unretained id *uip = (__unsafe_unretained id *)vp;
45
46   __strong id **sipp = (__strong id **)vp;
47   __weak id **wipp = (__weak id **)vp;
48   __autoreleasing id **aipp = (__autoreleasing id **)vp;
49   __unsafe_unretained id **uipp = (__unsafe_unretained id **)vp;
50
51   sip = vp; // expected-error{{implicit conversion of a non-Objective-C pointer type 'void *' to '__strong id *' is disallowed with ARC}}
52   wip = vp; // expected-error{{implicit conversion of a non-Objective-C pointer type 'void *' to '__weak id *' is disallowed with ARC}}
53   aip = vp; // expected-error{{implicit conversion of a non-Objective-C pointer type 'void *' to '__autoreleasing id *' is disallowed with ARC}}
54   uip = vp; // expected-error{{implicit conversion of a non-Objective-C pointer type 'void *' to '__unsafe_unretained id *' is disallowed with ARC}}
55 }
56
57 typedef void (^Block)();
58 typedef void (^Block_strong)() __strong;
59 typedef void (^Block_autoreleasing)() __autoreleasing;
60
61 @class NSString;
62
63 void ownership_transfer_in_cast(void *vp, Block *pblk) {
64   __strong NSString **sip = (NSString**)(__strong id *)vp;
65   __weak NSString **wip = (NSString**)(__weak id *)vp;
66   __autoreleasing id *aip = (id*)(__autoreleasing id *)vp;
67   __unsafe_unretained id *uip = (id*)(__unsafe_unretained id *)vp;
68
69   __strong id **sipp = (id**)(__strong id **)vp;
70   __weak id **wipp = (id**)(__weak id **)vp;
71   __autoreleasing id **aipp = (id**)(__autoreleasing id **)vp;
72   __unsafe_unretained id **uipp = (id**)(__unsafe_unretained id **)vp;
73
74   Block_strong blk_strong1;
75   Block_strong blk_strong2 = (Block)blk_strong1;
76   Block_autoreleasing *blk_auto = (Block*)pblk;
77 }