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 // rdar://problem/9629566 - temporary workaround
35 CFTypeRef cf5 = (__bridge_retain CFTypeRef)CreateSomething(); // expected-error {{unknown cast annotation __bridge_retain; did you mean __bridge_retained?}}
36 // CHECK: fix-it:"{{.*}}":{35:20-35:35}:"__bridge_retained"
39 CFTypeRef fixits(void) {
40 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 // 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 // CHECK: fix-it:"{{.*}}":{40:17-40:17}:"CFBridgingRelease("
43 // CHECK: fix-it:"{{.*}}":{40:36-40:36}:")"
45 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 // expected-note{{use __bridge to convert directly (no change in ownership)}} \
47 // expected-note{{use CFBridgingRetain call to make an ARC object available as a +1 'CFTypeRef' (aka 'const void *')}}
48 // CHECK: fix-it:"{{.*}}":{45:30-45:30}:"CFBridgingRetain("
49 // CHECK: fix-it:"{{.*}}":{45:47-45:47}:")"
51 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 // expected-note{{use __bridge to convert directly (no change in ownership)}} \
53 // expected-note{{use CFBridgingRetain call to make an ARC object available as a +1 'CFTypeRef' (aka 'const void *')}}
54 // CHECK: fix-it:"{{.*}}":{51:10-51:10}:"(__bridge CFTypeRef)"
55 // CHECK: fix-it:"{{.*}}":{51:10-51:10}:"CFBridgingRetain"
58 CFTypeRef fixitsWithSpace(id obj) {
59 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 // expected-note{{use __bridge to convert directly (no change in ownership)}} \
61 // expected-note{{use CFBridgingRetain call to make an ARC object available as a +1 'CFTypeRef' (aka 'const void *')}}
62 // CHECK: fix-it:"{{.*}}":{59:9-59:9}:"(__bridge CFTypeRef)"
63 // CHECK: fix-it:"{{.*}}":{59:9-59:9}:" CFBridgingRetain"
66 // rdar://problem/20107345
67 typedef const struct __attribute__((objc_bridge(id))) __CFAnnotatedObject *CFAnnotatedObjectRef;
68 CFAnnotatedObjectRef CFGetAnnotated(void);
70 void testObjCBridgeId(void) {
72 obj = (__bridge id)CFGetAnnotated();
73 obj = (__bridge NSString*)CFGetAnnotated();
74 obj = (__bridge_transfer id)CFGetAnnotated();
75 obj = (__bridge_transfer NSString*)CFGetAnnotated();
77 CFAnnotatedObjectRef ref;
78 ref = (__bridge CFAnnotatedObjectRef) CreateSomething();
79 ref = (__bridge CFAnnotatedObjectRef) CreateNSString();
80 ref = (__bridge_retained CFAnnotatedObjectRef) CreateSomething();
81 ref = (__bridge_retained CFAnnotatedObjectRef) CreateNSString();
85 typedef const struct __attribute__((objc_bridge(UIFont))) __CTFont * CTFontRef;
87 id testObjCBridgeUnknownTypeToId(CTFontRef font) {
88 id x = (__bridge id)font;