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