blob: 47476c83064d53b19949f40d057f0d8e6d3a8d8e [file] [log] [blame]
John McCalld1e40d52011-10-02 01:16:38 +00001// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fsyntax-only -fobjc-arc -fblocks -verify %s
2// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fsyntax-only -fblocks %s
John McCallf85e1932011-06-15 23:02:42 +00003
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();
John McCall18164422011-06-17 21:23:37 +000030 CFStringRef cf4 = (__bridge CFStringRef)CreateNSString();
31
32 // rdar://problem/9629566 - temporary workaround
John McCallb64915a2011-06-17 21:56:12 +000033 CFTypeRef cf5 = (__bridge_retain CFTypeRef)CreateSomething(); // expected-error {{unknown cast annotation __bridge_retain; did you mean __bridge_retained?}}
John McCallf85e1932011-06-15 23:02:42 +000034}
35
36void fixits() {
37 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}} \
38 // expected-note{{use __bridge to convert directly (no change in ownership)}} \
39 // expected-note{{use __bridge_transfer to transfer ownership of a +1 'CFTypeRef' (aka 'const void *') into ARC}}
40 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}} \
41 // expected-note{{use __bridge to convert directly (no change in ownership)}} \
42 // expected-note{{use __bridge_retained to make an ARC object available as a +1 'CFTypeRef' (aka 'const void *')}}
43}