1 // RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fsyntax-only -fobjc-arc -fblocks -verify %s
2 // RUN: not %clang_cc1 -triple x86_64-apple-darwin11 -fsyntax-only -fobjc-arc -fblocks -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
4 typedef const void *CFTypeRef;
5 CFTypeRef CFBridgingRetain(id X);
6 id CFBridgingRelease(CFTypeRef);
7 typedef const struct __CFString *CFStringRef;
12 CFTypeRef CFCreateSomething(void);
13 CFStringRef CFCreateString(void);
14 CFTypeRef CFGetSomething(void);
15 CFStringRef CFGetString(void);
17 id CreateSomething(void);
18 NSString *CreateNSString(void);
21 id obj1 = (__bridge_transfer id)CFCreateSomething();
22 id obj2 = (__bridge_transfer NSString*)CFCreateString();
23 (__bridge int*)CFCreateSomething(); // expected-error{{incompatible types casting 'CFTypeRef' (aka 'const void *') to 'int *' with a __bridge cast}}
24 id obj3 = (__bridge id)CFGetSomething();
25 id obj4 = (__bridge NSString*)CFGetString();
29 CFTypeRef cf1 = (__bridge_retained CFTypeRef)CreateSomething();
30 CFStringRef cf2 = (__bridge_retained CFStringRef)CreateNSString();
31 CFTypeRef cf3 = (__bridge CFTypeRef)CreateSomething();
32 CFStringRef cf4 = (__bridge CFStringRef)CreateNSString();
34 CFTypeRef cf5 = (__bridge_retain CFTypeRef)CreateSomething(); // expected-error {{unknown cast annotation __bridge_retain; did you mean __bridge_retained?}}
35 // CHECK: fix-it:"{{.*}}":{34:20-34:35}:"__bridge_retained"
38 CFTypeRef fixits(void) {
39 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}} \
40 // 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}}
41 // CHECK: fix-it:"{{.*}}":{39:17-39:17}:"CFBridgingRelease("
42 // CHECK: fix-it:"{{.*}}":{39:36-39:36}:")"
44 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}} \
45 // expected-note{{use __bridge to convert directly (no change in ownership)}} \
46 // expected-note{{use CFBridgingRetain call to make an ARC object available as a +1 'CFTypeRef' (aka 'const void *')}}
47 // CHECK: fix-it:"{{.*}}":{44:30-44:30}:"CFBridgingRetain("
48 // CHECK: fix-it:"{{.*}}":{44:47-44:47}:")"
50 return (obj1); // expected-error{{implicit conversion of Objective-C pointer type 'id' to C pointer type 'CFTypeRef' (aka 'const void *') requires a bridged cast}} \
51 // expected-note{{use __bridge to convert directly (no change in ownership)}} \
52 // expected-note{{use CFBridgingRetain call to make an ARC object available as a +1 'CFTypeRef' (aka 'const void *')}}
53 // CHECK: fix-it:"{{.*}}":{50:10-50:10}:"(__bridge CFTypeRef)"
54 // CHECK: fix-it:"{{.*}}":{50:10-50:10}:"CFBridgingRetain"
57 CFTypeRef fixitsWithSpace(id obj) {
58 return(obj); // expected-error{{implicit conversion of Objective-C pointer type 'id' to C pointer type 'CFTypeRef' (aka 'const void *') requires a bridged cast}} \
59 // expected-note{{use __bridge to convert directly (no change in ownership)}} \
60 // expected-note{{use CFBridgingRetain call to make an ARC object available as a +1 'CFTypeRef' (aka 'const void *')}}
61 // CHECK: fix-it:"{{.*}}":{58:9-58:9}:"(__bridge CFTypeRef)"
62 // CHECK: fix-it:"{{.*}}":{58:9-58:9}:" CFBridgingRetain"
65 typedef const struct __attribute__((objc_bridge(id))) __CFAnnotatedObject *CFAnnotatedObjectRef;
66 CFAnnotatedObjectRef CFGetAnnotated(void);
68 void testObjCBridgeId(void) {
70 obj = (__bridge id)CFGetAnnotated();
71 obj = (__bridge NSString*)CFGetAnnotated();
72 obj = (__bridge_transfer id)CFGetAnnotated();
73 obj = (__bridge_transfer NSString*)CFGetAnnotated();
75 CFAnnotatedObjectRef ref;
76 ref = (__bridge CFAnnotatedObjectRef) CreateSomething();
77 ref = (__bridge CFAnnotatedObjectRef) CreateNSString();
78 ref = (__bridge_retained CFAnnotatedObjectRef) CreateSomething();
79 ref = (__bridge_retained CFAnnotatedObjectRef) CreateNSString();
82 typedef const struct __attribute__((objc_bridge(UIFont))) __CTFont * CTFontRef;
84 id testObjCBridgeUnknownTypeToId(CTFontRef font) {
85 id x = (__bridge id)font;