1// RUN: %clang_cc1 -arcmt-check -verify -triple x86_64-apple-darwin10 %s 2// DISABLE: mingw32 3 4#include "Common.h" 5 6@interface NSString : NSObject 7-(id)string; 8-(id)newString; 9@end 10 11typedef const struct __CFString * CFStringRef; 12typedef const void * CFTypeRef; 13CFTypeRef CFBridgingRetain(id X); 14id CFBridgingRelease(CFTypeRef); 15 16void f(BOOL b) { 17 CFStringRef cfstr; 18 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}} \ 19 // expected-note{{use __bridge to convert directly (no change in ownership)}} \ 20 // expected-note{{use CFBridgingRelease call to transfer ownership of a +1 'CFStringRef' (aka 'const struct __CFString *') into ARC}} 21 void *vp = str; // expected-error {{requires a bridged cast}} expected-note {{use CFBridgingRetain call}} expected-note {{use __bridge}} 22} 23 24void f2(NSString *s) { 25 CFStringRef ref; 26 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}} \ 27 // expected-error {{bad receiver type 'CFStringRef' (aka 'const struct __CFString *')}} \ 28 // expected-note{{use __bridge to convert directly (no change in ownership)}} \ 29 // expected-note{{use CFBridgingRetain call to make an ARC object available as a +1 'CFStringRef' (aka 'const struct __CFString *')}} 30} 31 32CFStringRef f3() { 33 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}} \ 34 // expected-note {{remove the cast and change return type of function to 'NSString *' to have the object automatically autoreleased}} 35} 36