John McCall | d1e40d5 | 2011-10-02 01:16:38 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fsyntax-only -fobjc-arc -fblocks -verify %s |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 2 | |
| 3 | typedef const void *CFTypeRef; |
| 4 | typedef const struct __CFString *CFStringRef; |
| 5 | |
| 6 | @interface NSString |
| 7 | @end |
| 8 | |
| 9 | CFTypeRef CFCreateSomething(); |
| 10 | CFStringRef CFCreateString(); |
| 11 | CFTypeRef CFGetSomething(); |
| 12 | CFStringRef CFGetString(); |
| 13 | |
| 14 | id CreateSomething(); |
| 15 | NSString *CreateNSString(); |
| 16 | |
| 17 | void from_cf() { |
| 18 | id obj1 = (__bridge_transfer id)CFCreateSomething(); |
| 19 | id obj2 = (__bridge_transfer NSString*)CFCreateString(); |
| 20 | (__bridge int*)CFCreateSomething(); // expected-error{{incompatible types casting 'CFTypeRef' (aka 'const void *') to 'int *' with a __bridge cast}} |
| 21 | id obj3 = (__bridge id)CFGetSomething(); |
| 22 | id obj4 = (__bridge NSString*)CFGetString(); |
| 23 | } |
| 24 | |
| 25 | void to_cf(id obj) { |
| 26 | CFTypeRef cf1 = (__bridge_retained CFTypeRef)CreateSomething(); |
| 27 | CFStringRef cf2 = (__bridge_retained CFStringRef)CreateNSString(); |
| 28 | CFTypeRef cf3 = (__bridge CFTypeRef)CreateSomething(); |
John McCall | 1816442 | 2011-06-17 21:23:37 +0000 | [diff] [blame] | 29 | CFStringRef cf4 = (__bridge CFStringRef)CreateNSString(); |
| 30 | |
| 31 | // rdar://problem/9629566 - temporary workaround |
John McCall | b64915a | 2011-06-17 21:56:12 +0000 | [diff] [blame] | 32 | CFTypeRef cf5 = (__bridge_retain CFTypeRef)CreateSomething(); // expected-error {{unknown cast annotation __bridge_retain; did you mean __bridge_retained?}} |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | void fixits() { |
| 36 | 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}} \ |
| 37 | // expected-note{{use __bridge to convert directly (no change in ownership)}} \ |
Fariborz Jahanian | 7eb82f0 | 2012-01-31 23:42:37 +0000 | [diff] [blame] | 38 | // expected-note{{use CFBridgeRelease call to transfer ownership of a +1 'CFTypeRef' (aka 'const void *') into ARC}} |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 39 | 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}} \ |
| 40 | // expected-note{{use __bridge to convert directly (no change in ownership)}} \ |
Fariborz Jahanian | 7eb82f0 | 2012-01-31 23:42:37 +0000 | [diff] [blame] | 41 | // expected-note{{use CFBridgeRetain call to make an ARC object available as a +1 'CFTypeRef' (aka 'const void *')}} |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 42 | } |