Home | History | Annotate | Download | only in SemaObjCXX
      1 // RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fsyntax-only -fobjc-arc -fblocks -verify %s
      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 template<typename IdType, typename StringType, typename IntPtrType>
     18 void from_cf() {
     19   id obj1 = (__bridge_transfer IdType)CFCreateSomething();
     20   id obj2 = (__bridge_transfer StringType)CFCreateString();
     21   (__bridge IntPtrType)CFCreateSomething(); // expected-error{{incompatible types casting 'CFTypeRef' (aka 'const void *') to 'int *' with a __bridge cast}}
     22   id obj3 = (__bridge IdType)CFGetSomething();
     23   id obj4 = (__bridge StringType)CFGetString();
     24 }
     25 
     26 template void from_cf<id, NSString*, int*>(); // expected-note{{in instantiation of function template specialization}}
     27 
     28 template<typename IdType, typename StringType>
     29 void to_cf(id obj) {
     30   CFTypeRef cf1 = (__bridge_retained IdType)CreateSomething();
     31   CFStringRef cf2 = (__bridge_retained StringType)CreateNSString();
     32   CFTypeRef cf3 = (__bridge IdType)CreateSomething();
     33   CFStringRef cf4 = (__bridge StringType)CreateNSString(); 
     34 }
     35 
     36 template void to_cf<CFTypeRef, CFStringRef>(id);
     37