blob: 243edd613fdaaecb6daecd909c6dca5896f976a9 [file] [log] [blame]
Fariborz Jahanian4ad56862011-06-20 20:54:42 +00001// // RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fobjc-nonfragile-abi -fsyntax-only -fobjc-arc -verify %s
Fariborz Jahanian4ad56862011-06-20 20:54:42 +00002
3typedef const struct __CFString * CFStringRef;
4
John McCalle4fe2452011-10-01 01:01:08 +00005@interface Object
6@property CFStringRef property;
7- (CFStringRef) implicitProperty;
8- (CFStringRef) newString;
9- (CFStringRef) makeString;
Fariborz Jahanian4ad56862011-06-20 20:54:42 +000010@end
11
John McCalle4fe2452011-10-01 01:01:08 +000012extern Object *object;
13
14// rdar://9744349
15id test0(void) {
16 id p1 = (id)[object property];
17 id p2 = (__bridge_transfer id)[object property];
18 id p3 = (__bridge id)[object property];
19 return (id) object.property;
Fariborz Jahanian4ad56862011-06-20 20:54:42 +000020}
John McCalle4fe2452011-10-01 01:01:08 +000021
22// rdar://10140692
23CFStringRef unauditedString(void);
24CFStringRef plusOneString(void) __attribute__((cf_returns_retained));
25
26#pragma clang arc_cf_code_audited begin
27CFStringRef auditedString(void);
28CFStringRef auditedCreateString(void);
29#pragma clang arc_cf_code_audited end
30
31void test1(int cond) {
32 id x;
33 x = (id) auditedString();
34 x = (id) (cond ? auditedString() : (void*) 0);
35 x = (id) (cond ? (void*) 0 : auditedString());
36 x = (id) (cond ? (CFStringRef) @"help" : auditedString());
37
38 x = (id) unauditedString(); // expected-error {{requires a bridged cast}} expected-note {{use __bridge to}} expected-note {{use __bridge_transfer to}}
39 x = (id) (cond ? unauditedString() : (void*) 0); // expected-error {{requires a bridged cast}} expected-note {{use __bridge to}} expected-note {{use __bridge_transfer to}}
40 x = (id) (cond ? (void*) 0 : unauditedString()); // expected-error {{requires a bridged cast}} expected-note {{use __bridge to}} expected-note {{use __bridge_transfer to}}
41 x = (id) (cond ? (CFStringRef) @"help" : unauditedString()); // expected-error {{requires a bridged cast}} expected-note {{use __bridge to}} expected-note {{use __bridge_transfer to}}
42
43 x = (id) auditedCreateString(); // expected-error {{requires a bridged cast}} expected-note {{use __bridge to}} expected-note {{use __bridge_transfer to}}
44 x = (id) (cond ? auditedCreateString() : (void*) 0); // expected-error {{requires a bridged cast}} expected-note {{use __bridge to}} expected-note {{use __bridge_transfer to}}
45 x = (id) (cond ? (void*) 0 : auditedCreateString()); // expected-error {{requires a bridged cast}} expected-note {{use __bridge to}} expected-note {{use __bridge_transfer to}}
46 x = (id) (cond ? (CFStringRef) @"help" : auditedCreateString()); // expected-error {{requires a bridged cast}} expected-note {{use __bridge to}} expected-note {{use __bridge_transfer to}}
47
48 x = (id) [object property];
49 x = (id) (cond ? [object property] : (void*) 0);
50 x = (id) (cond ? (void*) 0 : [object property]);
51 x = (id) (cond ? (CFStringRef) @"help" : [object property]);
52
53 x = (id) object.property;
54 x = (id) (cond ? object.property : (void*) 0);
55 x = (id) (cond ? (void*) 0 : object.property);
56 x = (id) (cond ? (CFStringRef) @"help" : object.property);
57
58 x = (id) object.implicitProperty;
59 x = (id) (cond ? object.implicitProperty : (void*) 0);
60 x = (id) (cond ? (void*) 0 : object.implicitProperty);
61 x = (id) (cond ? (CFStringRef) @"help" : object.implicitProperty);
62
63 x = (id) [object makeString];
64 x = (id) (cond ? [object makeString] : (void*) 0);
65 x = (id) (cond ? (void*) 0 : [object makeString]);
66 x = (id) (cond ? (CFStringRef) @"help" : [object makeString]);
67
68 x = (id) [object newString];
69 x = (id) (cond ? [object newString] : (void*) 0);
70 x = (id) (cond ? (void*) 0 : [object newString]);
71 x = (id) (cond ? (CFStringRef) @"help" : [object newString]); // a bit questionable
72}