Home | History | Annotate | Download | only in SemaObjC
      1 // 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 
      4 typedef const void *CFTypeRef;
      5 typedef const struct __CFString *CFStringRef;
      6 
      7 @interface NSString
      8 @end
      9 
     10 CFTypeRef CFCreateSomething();
     11 CFStringRef CFCreateString();
     12 CFTypeRef CFGetSomething();
     13 CFStringRef CFGetString();
     14 
     15 id CreateSomething();
     16 NSString *CreateNSString();
     17 
     18 void 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 
     26 void 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   // rdar://problem/9629566 - temporary workaround
     33   CFTypeRef cf5 = (__bridge_retain CFTypeRef)CreateSomething(); // expected-error {{unknown cast annotation __bridge_retain; did you mean __bridge_retained?}}
     34 }
     35 
     36 void 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 }
     44