1*f4a2713aSLionel Sambuc// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fsyntax-only -fobjc-arc -fblocks -verify %s 2*f4a2713aSLionel Sambuc// RUN: not %clang_cc1 -triple x86_64-apple-darwin11 -fsyntax-only -fobjc-arc -fblocks -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s 3*f4a2713aSLionel Sambuc 4*f4a2713aSLionel Sambuctypedef const void *CFTypeRef; 5*f4a2713aSLionel SambucCFTypeRef CFBridgingRetain(id X); 6*f4a2713aSLionel Sambucid CFBridgingRelease(CFTypeRef); 7*f4a2713aSLionel Sambuctypedef const struct __CFString *CFStringRef; 8*f4a2713aSLionel Sambuc 9*f4a2713aSLionel Sambuc@interface NSString 10*f4a2713aSLionel Sambuc@end 11*f4a2713aSLionel Sambuc 12*f4a2713aSLionel SambucCFTypeRef CFCreateSomething(); 13*f4a2713aSLionel SambucCFStringRef CFCreateString(); 14*f4a2713aSLionel SambucCFTypeRef CFGetSomething(); 15*f4a2713aSLionel SambucCFStringRef CFGetString(); 16*f4a2713aSLionel Sambuc 17*f4a2713aSLionel Sambucid CreateSomething(); 18*f4a2713aSLionel SambucNSString *CreateNSString(); 19*f4a2713aSLionel Sambuc 20*f4a2713aSLionel Sambucvoid from_cf() { 21*f4a2713aSLionel Sambuc id obj1 = (__bridge_transfer id)CFCreateSomething(); 22*f4a2713aSLionel Sambuc id obj2 = (__bridge_transfer NSString*)CFCreateString(); 23*f4a2713aSLionel Sambuc (__bridge int*)CFCreateSomething(); // expected-error{{incompatible types casting 'CFTypeRef' (aka 'const void *') to 'int *' with a __bridge cast}} 24*f4a2713aSLionel Sambuc id obj3 = (__bridge id)CFGetSomething(); 25*f4a2713aSLionel Sambuc id obj4 = (__bridge NSString*)CFGetString(); 26*f4a2713aSLionel Sambuc} 27*f4a2713aSLionel Sambuc 28*f4a2713aSLionel Sambucvoid to_cf(id obj) { 29*f4a2713aSLionel Sambuc CFTypeRef cf1 = (__bridge_retained CFTypeRef)CreateSomething(); 30*f4a2713aSLionel Sambuc CFStringRef cf2 = (__bridge_retained CFStringRef)CreateNSString(); 31*f4a2713aSLionel Sambuc CFTypeRef cf3 = (__bridge CFTypeRef)CreateSomething(); 32*f4a2713aSLionel Sambuc CFStringRef cf4 = (__bridge CFStringRef)CreateNSString(); 33*f4a2713aSLionel Sambuc 34*f4a2713aSLionel Sambuc // rdar://problem/9629566 - temporary workaround 35*f4a2713aSLionel Sambuc CFTypeRef cf5 = (__bridge_retain CFTypeRef)CreateSomething(); // expected-error {{unknown cast annotation __bridge_retain; did you mean __bridge_retained?}} 36*f4a2713aSLionel Sambuc // CHECK: fix-it:"{{.*}}":{35:20-35:35}:"__bridge_retained" 37*f4a2713aSLionel Sambuc} 38*f4a2713aSLionel Sambuc 39*f4a2713aSLionel SambucCFTypeRef fixits() { 40*f4a2713aSLionel Sambuc 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}} \ 41*f4a2713aSLionel Sambuc // expected-note{{use __bridge to convert directly (no change in ownership)}} expected-note{{use CFBridgingRelease call to transfer ownership of a +1 'CFTypeRef' (aka 'const void *') into ARC}} 42*f4a2713aSLionel Sambuc // CHECK: fix-it:"{{.*}}":{40:17-40:17}:"CFBridgingRelease(" 43*f4a2713aSLionel Sambuc // CHECK: fix-it:"{{.*}}":{40:36-40:36}:")" 44*f4a2713aSLionel Sambuc 45*f4a2713aSLionel Sambuc 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}} \ 46*f4a2713aSLionel Sambuc // expected-note{{use __bridge to convert directly (no change in ownership)}} \ 47*f4a2713aSLionel Sambuc // expected-note{{use CFBridgingRetain call to make an ARC object available as a +1 'CFTypeRef' (aka 'const void *')}} 48*f4a2713aSLionel Sambuc // CHECK: fix-it:"{{.*}}":{45:30-45:30}:"CFBridgingRetain(" 49*f4a2713aSLionel Sambuc // CHECK: fix-it:"{{.*}}":{45:47-45:47}:")" 50*f4a2713aSLionel Sambuc 51*f4a2713aSLionel Sambuc return (obj1); // expected-error{{implicit conversion of Objective-C pointer type 'id' to C pointer type 'CFTypeRef' (aka 'const void *') requires a bridged cast}} \ 52*f4a2713aSLionel Sambuc // expected-note{{use __bridge to convert directly (no change in ownership)}} \ 53*f4a2713aSLionel Sambuc // expected-note{{use CFBridgingRetain call to make an ARC object available as a +1 'CFTypeRef' (aka 'const void *')}} 54*f4a2713aSLionel Sambuc // CHECK: fix-it:"{{.*}}":{51:10-51:10}:"(__bridge CFTypeRef)" 55*f4a2713aSLionel Sambuc // CHECK: fix-it:"{{.*}}":{51:10-51:10}:"CFBridgingRetain" 56*f4a2713aSLionel Sambuc} 57*f4a2713aSLionel Sambuc 58*f4a2713aSLionel SambucCFTypeRef fixitsWithSpace(id obj) { 59*f4a2713aSLionel Sambuc return(obj); // expected-error{{implicit conversion of Objective-C pointer type 'id' to C pointer type 'CFTypeRef' (aka 'const void *') requires a bridged cast}} \ 60*f4a2713aSLionel Sambuc // expected-note{{use __bridge to convert directly (no change in ownership)}} \ 61*f4a2713aSLionel Sambuc // expected-note{{use CFBridgingRetain call to make an ARC object available as a +1 'CFTypeRef' (aka 'const void *')}} 62*f4a2713aSLionel Sambuc // CHECK: fix-it:"{{.*}}":{59:9-59:9}:"(__bridge CFTypeRef)" 63*f4a2713aSLionel Sambuc // CHECK: fix-it:"{{.*}}":{59:9-59:9}:" CFBridgingRetain" 64*f4a2713aSLionel Sambuc} 65