blob: 56efe81d608b0d1a84f96157d456343d4c7e2487 [file] [log] [blame]
John McCalld1e40d52011-10-02 01:16:38 +00001// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fsyntax-only -fobjc-arc -fblocks -verify %s
John McCallf85e1932011-06-15 23:02:42 +00002
3typedef const void *CFTypeRef;
Fariborz Jahanian52b62362012-02-01 22:56:20 +00004CFTypeRef CFBridgingRetain(id X);
5id CFBridgingRelease(CFTypeRef);
John McCallf85e1932011-06-15 23:02:42 +00006typedef const struct __CFString *CFStringRef;
7
8@interface NSString
9@end
10
11CFTypeRef CFCreateSomething();
12CFStringRef CFCreateString();
13CFTypeRef CFGetSomething();
14CFStringRef CFGetString();
15
16id CreateSomething();
17NSString *CreateNSString();
18
19void from_cf() {
20 id obj1 = (__bridge_transfer id)CFCreateSomething();
21 id obj2 = (__bridge_transfer NSString*)CFCreateString();
22 (__bridge int*)CFCreateSomething(); // expected-error{{incompatible types casting 'CFTypeRef' (aka 'const void *') to 'int *' with a __bridge cast}}
23 id obj3 = (__bridge id)CFGetSomething();
24 id obj4 = (__bridge NSString*)CFGetString();
25}
26
27void to_cf(id obj) {
28 CFTypeRef cf1 = (__bridge_retained CFTypeRef)CreateSomething();
29 CFStringRef cf2 = (__bridge_retained CFStringRef)CreateNSString();
30 CFTypeRef cf3 = (__bridge CFTypeRef)CreateSomething();
John McCall18164422011-06-17 21:23:37 +000031 CFStringRef cf4 = (__bridge CFStringRef)CreateNSString();
32
33 // rdar://problem/9629566 - temporary workaround
John McCallb64915a2011-06-17 21:56:12 +000034 CFTypeRef cf5 = (__bridge_retain CFTypeRef)CreateSomething(); // expected-error {{unknown cast annotation __bridge_retain; did you mean __bridge_retained?}}
John McCallf85e1932011-06-15 23:02:42 +000035}
36
37void fixits() {
38 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}} \
39 // expected-note{{use __bridge to convert directly (no change in ownership)}} \
Fariborz Jahanian52b62362012-02-01 22:56:20 +000040 // expected-note{{use CFBridgingRelease call to transfer ownership of a +1 'CFTypeRef' (aka 'const void *') into ARC}}
John McCallf85e1932011-06-15 23:02:42 +000041 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}} \
42 // expected-note{{use __bridge to convert directly (no change in ownership)}} \
Fariborz Jahanian52b62362012-02-01 22:56:20 +000043 // expected-note{{use CFBridgingRetain call to make an ARC object available as a +1 'CFTypeRef' (aka 'const void *')}}
John McCallf85e1932011-06-15 23:02:42 +000044}