1 // RUN: %clang_cc1 -arcmt-action=check -verify -triple x86_64-apple-darwin10 %s
5 typedef const struct __CFString * CFStringRef;
6 typedef const void * CFTypeRef;
7 CFTypeRef CFBridgingRetain(id X);
8 id CFBridgingRelease(CFTypeRef);
11 CFStringRef sref_member;
14 @interface NSString : NSObject {
22 @implementation NSString
27 return strS->sref_member;
30 return sref; // expected-error {{implicit conversion of C pointer type 'CFStringRef' (aka 'const struct __CFString *') to Objective-C pointer type 'id' requires a bridged cast}} \
31 // expected-note{{use __bridge to convert directly (no change in ownership)}} \
32 // expected-note{{use CFBridgingRelease call to transfer ownership of a +1 'CFStringRef' (aka 'const struct __CFString *') into ARC}}
38 NSString *str = (NSString *)cfstr; // expected-error {{cast of C pointer type 'CFStringRef' (aka 'const struct __CFString *') to Objective-C pointer type 'NSString *' requires a bridged cast}} \
39 // expected-note{{use __bridge to convert directly (no change in ownership)}} \
40 // expected-note{{use CFBridgingRelease call to transfer ownership of a +1 'CFStringRef' (aka 'const struct __CFString *') into ARC}}
41 void *vp = str; // expected-error {{requires a bridged cast}} expected-note {{use CFBridgingRetain call}} expected-note {{use __bridge}}
44 void f2(NSString *s) {
46 ref = [(CFStringRef)[s string] retain]; // expected-error {{cast of Objective-C pointer type 'id' to C pointer type 'CFStringRef' (aka 'const struct __CFString *') requires a bridged cast}} \
47 // expected-error {{bad receiver type 'CFStringRef' (aka 'const struct __CFString *')}} \
48 // expected-note{{use __bridge to convert directly (no change in ownership)}} \
49 // expected-note{{use CFBridgingRetain call to make an ARC object available as a +1 'CFStringRef' (aka 'const struct __CFString *')}}
52 CFStringRef f3(void) {
53 return (CFStringRef)[[[NSString alloc] init] autorelease]; // expected-error {{it is not safe to cast to 'CFStringRef' the result of 'autorelease' message; a __bridge cast may result in a pointer to a destroyed object and a __bridge_retained may leak the object}} \
54 // expected-note {{remove the cast and change return type of function to 'NSString *' to have the object automatically autoreleased}}
57 extern void NSLog(NSString *format, ...);
59 void f4(NSString *s) {
60 NSLog(@"%@", (CFStringRef)s); // expected-error {{cast of Objective-C pointer type 'NSString *' to C pointer type 'CFStringRef' (aka 'const struct __CFString *') requires a bridged cast}} \
61 // expected-note{{use __bridge to convert directly (no change in ownership)}} \
62 // expected-note{{use CFBridgingRetain call to make an ARC object available as a +1 'CFStringRef' (aka 'const struct __CFString *')}}