blob: 227cce2248fcb8a813a4f5a333ebad48c2c94f1c [file] [log] [blame]
John McCallf85e1932011-06-15 23:02:42 +00001// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fobjc-nonfragile-abi -fsyntax-only -fobjc-arc -fblocks -verify %s
2// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fobjc-nonfragile-abi -fsyntax-only -fblocks %s
3
4typedef const void *CFTypeRef;
5typedef const struct __CFString *CFStringRef;
6
7@interface NSString
8@end
9
10CFTypeRef CFCreateSomething();
11CFStringRef CFCreateString();
12CFTypeRef CFGetSomething();
13CFStringRef CFGetString();
14
15id CreateSomething();
16NSString *CreateNSString();
17
18void from_cf() {
19 id obj1 = (__bridge_transfer id)CFCreateSomething();
20 id obj2 = (__bridge_transfer NSString*)CFCreateString();
21 (__bridge int*)CFCreateSomething(); // expected-error{{incompatible types casting 'CFTypeRef' (aka 'const void *') to 'int *' with a __bridge cast}}
22 id obj3 = (__bridge id)CFGetSomething();
23 id obj4 = (__bridge NSString*)CFGetString();
24}
25
26void to_cf(id obj) {
27 CFTypeRef cf1 = (__bridge_retained CFTypeRef)CreateSomething();
28 CFStringRef cf2 = (__bridge_retained CFStringRef)CreateNSString();
29 CFTypeRef cf3 = (__bridge CFTypeRef)CreateSomething();
30 CFStringRef cf4 = (__bridge CFStringRef)CreateNSString();
31}
32
33void fixits() {
34 id obj1 = (id)CFCreateSomething(); // expected-error{{cast of C pointer type 'CFTypeRef' (aka 'const void *') to Objective-C pointer type 'id' requires a bridged cast}} \
35 // expected-note{{use __bridge to convert directly (no change in ownership)}} \
36 // expected-note{{use __bridge_transfer to transfer ownership of a +1 'CFTypeRef' (aka 'const void *') into ARC}}
37 CFTypeRef cf1 = (CFTypeRef)CreateSomething(); // expected-error{{cast of Objective-C pointer type 'id' to C pointer type 'CFTypeRef' (aka 'const void *') requires a bridged cast}} \
38 // expected-note{{use __bridge to convert directly (no change in ownership)}} \
39 // expected-note{{use __bridge_retained to make an ARC object available as a +1 'CFTypeRef' (aka 'const void *')}}
40}