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 38 // rdar://problem/20107345 39 typedef const struct __attribute__((objc_bridge(id))) __CFAnnotatedObject *CFAnnotatedObjectRef; 40 CFAnnotatedObjectRef CFGetAnnotated(); 41 42 void testObjCBridgeId() { 43 id obj; 44 obj = (__bridge id)CFGetAnnotated(); 45 obj = (__bridge NSString*)CFGetAnnotated(); 46 obj = (__bridge_transfer id)CFGetAnnotated(); 47 obj = (__bridge_transfer NSString*)CFGetAnnotated(); 48 49 CFAnnotatedObjectRef ref; 50 ref = (__bridge CFAnnotatedObjectRef) CreateSomething(); 51 ref = (__bridge CFAnnotatedObjectRef) CreateNSString(); 52 ref = (__bridge_retained CFAnnotatedObjectRef) CreateSomething(); 53 ref = (__bridge_retained CFAnnotatedObjectRef) CreateNSString(); 54 } 55