blob: c8f4d0d1661af0bc2062bd1ceb1119363cf90ae3 [file] [log] [blame]
John McCall9b0a7ce2011-10-02 01:16:38 +00001// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fsyntax-only -fobjc-arc -fblocks -verify %s
Jordan Rose288c4212012-06-07 01:10:31 +00002// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fsyntax-only -fobjc-arc -fblocks -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
John McCall31168b02011-06-15 23:02:42 +00003
4typedef const void *CFTypeRef;
Fariborz Jahanian30febeb2012-02-01 22:56:20 +00005CFTypeRef CFBridgingRetain(id X);
6id CFBridgingRelease(CFTypeRef);
John McCall31168b02011-06-15 23:02:42 +00007typedef const struct __CFString *CFStringRef;
8
9@interface NSString
10@end
11
12CFTypeRef CFCreateSomething();
13CFStringRef CFCreateString();
14CFTypeRef CFGetSomething();
15CFStringRef CFGetString();
16
17id CreateSomething();
18NSString *CreateNSString();
19
20void 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
28void to_cf(id obj) {
29 CFTypeRef cf1 = (__bridge_retained CFTypeRef)CreateSomething();
30 CFStringRef cf2 = (__bridge_retained CFStringRef)CreateNSString();
31 CFTypeRef cf3 = (__bridge CFTypeRef)CreateSomething();
John McCall0c329252011-06-17 21:23:37 +000032 CFStringRef cf4 = (__bridge CFStringRef)CreateNSString();
33
34 // rdar://problem/9629566 - temporary workaround
John McCall0c07bee2011-06-17 21:56:12 +000035 CFTypeRef cf5 = (__bridge_retain CFTypeRef)CreateSomething(); // expected-error {{unknown cast annotation __bridge_retain; did you mean __bridge_retained?}}
Jordan Rose288c4212012-06-07 01:10:31 +000036 // CHECK: fix-it:"{{.*}}":{35:20-35:35}:"__bridge_retained"
John McCall31168b02011-06-15 23:02:42 +000037}
38
Jordan Rose288c4212012-06-07 01:10:31 +000039CFTypeRef fixits() {
John McCall31168b02011-06-15 23:02:42 +000040 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}} \
Fariborz Jahanian84c97ca2012-07-27 21:34:23 +000041 // expected-note{{use __bridge to convert directly (no change in ownership)}} \
Fariborz Jahanian30febeb2012-02-01 22:56:20 +000042 // expected-note{{use CFBridgingRelease call to transfer ownership of a +1 'CFTypeRef' (aka 'const void *') into ARC}}
Fariborz Jahanian84c97ca2012-07-27 21:34:23 +000043 // CHECK: fix-it:"{{.*}}":{40:14-40:14}:"__bridge "
Jordan Rose288c4212012-06-07 01:10:31 +000044 // CHECK: fix-it:"{{.*}}":{40:17-40:17}:"CFBridgingRelease("
45 // CHECK: fix-it:"{{.*}}":{40:36-40:36}:")"
46
John McCall31168b02011-06-15 23:02:42 +000047 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}} \
Fariborz Jahanian84c97ca2012-07-27 21:34:23 +000048 // expected-note{{use __bridge to convert directly (no change in ownership)}} \
Fariborz Jahanian30febeb2012-02-01 22:56:20 +000049 // expected-note{{use CFBridgingRetain call to make an ARC object available as a +1 'CFTypeRef' (aka 'const void *')}}
Fariborz Jahanian84c97ca2012-07-27 21:34:23 +000050 // CHECK: fix-it:"{{.*}}":{47:20-47:20}:"__bridge "
51 // CHECK: fix-it:"{{.*}}":{47:30-47:30}:"CFBridgingRetain("
52 // CHECK: fix-it:"{{.*}}":{47:47-47:47}:")"
Jordan Rose288c4212012-06-07 01:10:31 +000053
54 return (obj1); // expected-error{{implicit conversion of Objective-C pointer type 'id' to C pointer type 'CFTypeRef' (aka 'const void *') requires a bridged cast}} \
Fariborz Jahanian84c97ca2012-07-27 21:34:23 +000055 // expected-note{{use __bridge to convert directly (no change in ownership)}} \
Jordan Rose288c4212012-06-07 01:10:31 +000056 // expected-note{{use CFBridgingRetain call to make an ARC object available as a +1 'CFTypeRef' (aka 'const void *')}}
Fariborz Jahanian84c97ca2012-07-27 21:34:23 +000057 // CHECK: fix-it:"{{.*}}":{54:10-54:10}:"(__bridge CFTypeRef)"
58 // CHECK: fix-it:"{{.*}}":{54:10-54:10}:"CFBridgingRetain"
Jordan Rose288c4212012-06-07 01:10:31 +000059}
60
61CFTypeRef fixitsWithSpace(id obj) {
62 return(obj); // expected-error{{implicit conversion of Objective-C pointer type 'id' to C pointer type 'CFTypeRef' (aka 'const void *') requires a bridged cast}} \
Fariborz Jahanian84c97ca2012-07-27 21:34:23 +000063 // expected-note{{use __bridge to convert directly (no change in ownership)}} \
Jordan Rose288c4212012-06-07 01:10:31 +000064 // expected-note{{use CFBridgingRetain call to make an ARC object available as a +1 'CFTypeRef' (aka 'const void *')}}
Fariborz Jahanian84c97ca2012-07-27 21:34:23 +000065 // CHECK: fix-it:"{{.*}}":{62:9-62:9}:"(__bridge CFTypeRef)"
66 // CHECK: fix-it:"{{.*}}":{62:9-62:9}:" CFBridgingRetain"
John McCall31168b02011-06-15 23:02:42 +000067}