Home | History | Annotate | Download | only in SemaObjC
      1 // RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fsyntax-only -fblocks -verify %s
      2 // rdar://10597832
      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(); // expected-warning {{'__bridge_transfer' casts have no effect when not using ARC}}
     20   id obj2 = (__bridge_transfer NSString*)CFCreateString(); // expected-warning {{'__bridge_transfer' casts have no effect when not using ARC}}
     21   (__bridge int*)CFCreateSomething(); // expected-warning {{expression result unused}}
     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(); // expected-warning {{'__bridge_retained' casts have no effect when not using ARC}}
     28   CFStringRef cf2 = (__bridge_retained CFStringRef)CreateNSString(); // expected-warning {{'__bridge_retained' casts have no effect when not using ARC}}
     29   CFTypeRef cf3 = (__bridge CFTypeRef)CreateSomething();
     30   CFStringRef cf4 = (__bridge CFStringRef)CreateNSString();
     31 }
     32 
     33 void fixits() {
     34   id obj1 = (id)CFCreateSomething();
     35   CFTypeRef cf1 = (CFTypeRef)CreateSomething();
     36 }
     37 
     38 #pragma clang diagnostic ignored "-Warc-bridge-casts-disallowed-in-nonarc"
     39 
     40 void to_cf_ignored(id obj) {
     41   CFTypeRef cf1 = (__bridge_retained CFTypeRef)CreateSomething(); // no-warning
     42   CFTypeRef cf3 = (__bridge CFTypeRef)CreateSomething(); // no-warning
     43 }
     44