1 // RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fsyntax-only -fobjc-arc -verify %s
3 typedef const struct __CFString * CFStringRef;
4 typedef const void * CFTypeRef;
5 extern "C" CFTypeRef CFBridgingRetain(id X);
6 extern "C" id CFBridgingRelease(CFTypeRef);
10 @property CFStringRef property;
11 - (CFStringRef) implicitProperty;
12 - (CFStringRef) newString;
13 - (CFStringRef) makeString;
16 extern Object *object;
19 id p1 = (id)[object property];
20 id p2 = (__bridge_transfer id)[object property];
21 id p3 = (__bridge id)[object property];
22 return (id) object.property;
25 CFStringRef unauditedString(void);
26 CFStringRef plusOneString(void) __attribute__((cf_returns_retained));
28 #pragma clang arc_cf_code_audited begin
29 CFStringRef auditedString(void);
30 CFStringRef auditedCreateString(void);
31 #pragma clang arc_cf_code_audited end
33 void test1(int cond) {
35 x = (id) auditedString();
36 x = (id) (cond ? auditedString() : (void*) 0);
37 x = (id) (cond ? (void*) 0 : auditedString());
38 x = (id) (cond ? (CFStringRef) @"help" : auditedString());
40 x = (id) unauditedString(); // expected-error {{requires a bridged cast}} expected-note {{use __bridge to}} expected-note {{use CFBridgingRelease call to}}
41 x = (id) (cond ? unauditedString() : (void*) 0); // expected-error {{requires a bridged cast}} expected-note {{use __bridge to}} expected-note {{use CFBridgingRelease call to}}
42 x = (id) (cond ? (void*) 0 : unauditedString()); // expected-error {{requires a bridged cast}} expected-note {{use __bridge to}} expected-note {{use CFBridgingRelease call to}}
43 x = (id) (cond ? (CFStringRef) @"help" : unauditedString()); // expected-error {{requires a bridged cast}} expected-note {{use __bridge to}} expected-note {{use CFBridgingRelease call to}}
45 x = (id) auditedCreateString(); // expected-error {{requires a bridged cast}} expected-note {{use CFBridgingRelease call to}}
46 x = (id) (cond ? auditedCreateString() : (void*) 0); // expected-error {{requires a bridged cast}} expected-note {{use CFBridgingRelease call to}}
47 x = (id) (cond ? (void*) 0 : auditedCreateString()); // expected-error {{requires a bridged cast}} expected-note {{use CFBridgingRelease call to}}
48 x = (id) (cond ? (CFStringRef) @"help" : auditedCreateString()); // expected-error {{requires a bridged cast}} expected-note {{use CFBridgingRelease call to}}
50 x = (id) [object property];
51 x = (id) (cond ? [object property] : (void*) 0);
52 x = (id) (cond ? (void*) 0 : [object property]);
53 x = (id) (cond ? (CFStringRef) @"help" : [object property]);
55 x = (id) object.property;
56 x = (id) (cond ? object.property : (void*) 0);
57 x = (id) (cond ? (void*) 0 : object.property);
58 x = (id) (cond ? (CFStringRef) @"help" : object.property);
60 x = (id) object.implicitProperty;
61 x = (id) (cond ? object.implicitProperty : (void*) 0);
62 x = (id) (cond ? (void*) 0 : object.implicitProperty);
63 x = (id) (cond ? (CFStringRef) @"help" : object.implicitProperty);
65 x = (id) [object makeString];
66 x = (id) (cond ? [object makeString] : (void*) 0);
67 x = (id) (cond ? (void*) 0 : [object makeString]);
68 x = (id) (cond ? (CFStringRef) @"help" : [object makeString]);
70 x = (id) [object newString];
71 x = (id) (cond ? [object newString] : (void*) 0);
72 x = (id) (cond ? (void*) 0 : [object newString]);
73 x = (id) (cond ? (CFStringRef) @"help" : [object newString]); // a bit questionable
77 - (void) takeOrdinary: (CFStringRef) arg;
78 - (void) takeVariadic: (int) n, ...;
79 - (void) takeConsumed: (CFStringRef __attribute__((cf_consumed))) arg;
81 void testCFTaker(CFTaker *taker, id string) {
82 [taker takeOrdinary: (CFStringRef) string];
83 [taker takeVariadic: 1, (CFStringRef) string];
84 [taker takeConsumed: (CFStringRef) string]; // expected-error {{cast of Objective-C pointer type 'id' to C pointer type 'CFStringRef'}} expected-note {{use __bridge to}} expected-note {{use CFBridgingRetain call to}}
87 void takeCFOrdinaryUnaudited(CFStringRef arg);
88 void takeCFVariadicUnaudited(int n, ...);
89 void takeCFConsumedUnaudited(CFStringRef __attribute__((cf_consumed)) arg);
90 #pragma clang arc_cf_code_audited begin
91 void takeCFOrdinaryAudited(CFStringRef arg);
92 void takeCFVariadicAudited(int n, ...);
93 void takeCFConsumedAudited(CFStringRef __attribute__((cf_consumed)) arg);
94 #pragma clang arc_cf_code_audited end
96 void testTakerFunctions(id string) {
97 takeCFOrdinaryUnaudited((CFStringRef) string); // expected-error {{cast of Objective-C pointer type 'id' to C pointer type 'CFStringRef'}} expected-note {{use __bridge to}} expected-note {{use CFBridgingRetain call to}}
98 takeCFVariadicUnaudited(1, (CFStringRef) string); // expected-error {{cast of Objective-C pointer type 'id' to C pointer type 'CFStringRef'}} expected-note {{use __bridge to}} expected-note {{use CFBridgingRetain call to}}
99 takeCFConsumedUnaudited((CFStringRef) string); // expected-error {{cast of Objective-C pointer type 'id' to C pointer type 'CFStringRef'}} expected-note {{use __bridge to}} expected-note {{use CFBridgingRetain call to}}
101 void (*taker)(CFStringRef) = 0;
102 taker((CFStringRef) string); // expected-error {{cast of Objective-C pointer type 'id' to C pointer type 'CFStringRef'}} expected-note {{use __bridge to}} expected-note {{use CFBridgingRetain call to}}
104 takeCFOrdinaryAudited((CFStringRef) string);
105 takeCFVariadicAudited(1, (CFStringRef) string);
106 takeCFConsumedAudited((CFStringRef) string); // expected-error {{cast of Objective-C pointer type 'id' to C pointer type 'CFStringRef'}} expected-note {{use __bridge to}} expected-note {{use CFBridgingRetain call to}}
111 void rdar12788838() {
112 void *foo = reinterpret_cast<void *>(obj); // expected-error {{cast of Objective-C pointer type 'id' to C pointer type 'void *' requires a bridged cast}} \
113 // expected-note {{use __bridge with C-style cast to convert directly}} \
114 // expected-note {{use CFBridgingRetain call to make an ARC object available as a +1 'void *'}}