summaryrefslogtreecommitdiff
path: root/clang/test/SemaObjC/arc-type-conversion.m
diff options
context:
space:
mode:
authorJohn McCall <rjmccall@apple.com>2011-06-15 23:02:42 +0000
committerJohn McCall <rjmccall@apple.com>2011-06-15 23:02:42 +0000
commitc9b860d9bb3e347dfa4189c53df62f95cb197f42 (patch)
treef068fbf220f33a8483f3f75e6a0b8e9f5170c9e3 /clang/test/SemaObjC/arc-type-conversion.m
parentd8499d9cf9cfffa4d41b201ebc8e9b0bdcb0fd72 (diff)
Automatic Reference Counting.
Language-design credit goes to a lot of people, but I particularly want to single out Blaine Garst and Patrick Beard for their contributions. Compiler implementation credit goes to Argyrios, Doug, Fariborz, and myself, in no particular order.
Diffstat (limited to 'clang/test/SemaObjC/arc-type-conversion.m')
-rw-r--r--clang/test/SemaObjC/arc-type-conversion.m55
1 files changed, 55 insertions, 0 deletions
diff --git a/clang/test/SemaObjC/arc-type-conversion.m b/clang/test/SemaObjC/arc-type-conversion.m
new file mode 100644
index 00000000000..e723a633171
--- /dev/null
+++ b/clang/test/SemaObjC/arc-type-conversion.m
@@ -0,0 +1,55 @@
+// RUN: %clang_cc1 -fsyntax-only -fobjc-arc -fobjc-nonfragile-abi -verify %s
+
+void * cvt(id arg)
+{
+ void* voidp_val;
+ (void)(int*)arg; // expected-error {{cast of an Objective-C pointer to 'int *' is disallowed with ARC}}
+ (void)(id)arg;
+ (void)(__autoreleasing id*)arg; // expected-error {{cast of an Objective-C pointer to '__autoreleasing id *' is disallowed with ARC}}
+ (void)(id*)arg; // expected-error {{pointer to non-const type 'id' with no explicit lifetime}} expected-error {{cast of an Objective-C pointer to '__autoreleasing id *' is disallowed with ARC}}
+
+ (void)(__autoreleasing id**)voidp_val;
+ (void)(void*)voidp_val;
+ (void)(void**)arg; // expected-error {{cast of an Objective-C pointer to 'void **' is disallowed with ARC}}
+ cvt((void*)arg); // expected-error {{cast of Objective-C pointer type 'id' to C pointer type 'void *' requires a bridged cast}} \
+ // expected-error {{implicit conversion of a non-Objective-C pointer type 'void *' to 'id' is disallowed with ARC}} \
+ // expected-note{{use __bridge to convert directly (no change in ownership)}} \
+ // expected-note{{use __bridge_retained to make an ARC object available as a +1 'void *'}}
+ cvt(0);
+ (void)(__strong id**)(0);
+ return arg; // expected-error {{implicit conversion of an Objective-C pointer to 'void *' is disallowed with ARC}}
+}
+
+void to_void(__strong id *sip, __weak id *wip,
+ __autoreleasing id *aip,
+ __unsafe_unretained id *uip) {
+ void *vp1 = sip;
+ void *vp2 = wip;
+ void *vp3 = aip;
+ void *vp4 = uip;
+ (void)(void*)sip;
+ (void)(void*)wip;
+ (void)(void*)aip;
+ (void)(void*)uip;
+ (void)(void*)&sip;
+ (void)(void*)&wip;
+ (void)(void*)&aip;
+ (void)(void*)&uip;
+}
+
+void from_void(void *vp) {
+ __strong id *sip = (__strong id *)vp;
+ __weak id *wip = (__weak id *)vp;
+ __autoreleasing id *aip = (__autoreleasing id *)vp;
+ __unsafe_unretained id *uip = (__unsafe_unretained id *)vp;
+
+ __strong id **sipp = (__strong id **)vp;
+ __weak id **wipp = (__weak id **)vp;
+ __autoreleasing id **aipp = (__autoreleasing id **)vp;
+ __unsafe_unretained id **uipp = (__unsafe_unretained id **)vp;
+
+ sip = vp; // expected-error{{implicit conversion of a non-Objective-C pointer type 'void *' to '__strong id *' is disallowed with ARC}}
+ wip = vp; // expected-error{{implicit conversion of a non-Objective-C pointer type 'void *' to '__weak id *' is disallowed with ARC}}
+ aip = vp; // expected-error{{implicit conversion of a non-Objective-C pointer type 'void *' to '__autoreleasing id *' is disallowed with ARC}}
+ uip = vp; // expected-error{{implicit conversion of a non-Objective-C pointer type 'void *' to '__unsafe_unretained id *' is disallowed with ARC}}
+}