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 |
3 | |
4 | typedef const void *CFTypeRef; |
5 | CFTypeRef CFBridgingRetain(id X); |
6 | id CFBridgingRelease(CFTypeRef); |
7 | typedef const struct __CFString *CFStringRef; |
8 | |
9 | @interface NSString |
10 | @end |
11 | |
12 | CFTypeRef CFCreateSomething(); |
13 | CFStringRef CFCreateString(); |
14 | CFTypeRef CFGetSomething(); |
15 | CFStringRef CFGetString(); |
16 | |
17 | id CreateSomething(); |
18 | NSString *CreateNSString(); |
19 | |
20 | void from_cf() { |
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(); |
26 | } |
27 | |
28 | void to_cf(id obj) { |
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(); |
33 | |
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" |
37 | } |
38 | |
39 | CFTypeRef fixits() { |
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}:")" |
44 | |
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}:")" |
50 | |
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" |
56 | } |
57 | |
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" |
64 | } |
65 | |
66 | // rdar://problem/20107345 |
67 | typedef const struct __attribute__((objc_bridge(id))) __CFAnnotatedObject *CFAnnotatedObjectRef; |
68 | CFAnnotatedObjectRef CFGetAnnotated(); |
69 | |
70 | void testObjCBridgeId() { |
71 | id obj; |
72 | obj = (__bridge id)CFGetAnnotated(); |
73 | obj = (__bridge NSString*)CFGetAnnotated(); |
74 | obj = (__bridge_transfer id)CFGetAnnotated(); |
75 | obj = (__bridge_transfer NSString*)CFGetAnnotated(); |
76 | |
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(); |
82 | } |
83 | |
84 | // rdar://20113785 |
85 | typedef const struct __attribute__((objc_bridge(UIFont))) __CTFont * CTFontRef; |
86 | |
87 | id testObjCBridgeUnknownTypeToId(CTFontRef font) { |
88 | id x = (__bridge id)font; |
89 | return x; |
90 | } |
91 | |
92 | |