| Fariborz Jahanian | 4ad5686 | 2011-06-20 20:54:42 +0000 | [diff] [blame] | 1 | // // RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fobjc-nonfragile-abi -fsyntax-only -fobjc-arc -verify %s |
| Fariborz Jahanian | 4ad5686 | 2011-06-20 20:54:42 +0000 | [diff] [blame] | 2 | |
| 3 | typedef const struct __CFString * CFStringRef; |
| 4 | |
| John McCall | e4fe245 | 2011-10-01 01:01:08 +0000 | [diff] [blame^] | 5 | @interface Object |
| 6 | @property CFStringRef property; |
| 7 | - (CFStringRef) implicitProperty; |
| 8 | - (CFStringRef) newString; |
| 9 | - (CFStringRef) makeString; |
| Fariborz Jahanian | 4ad5686 | 2011-06-20 20:54:42 +0000 | [diff] [blame] | 10 | @end |
| 11 | |
| John McCall | e4fe245 | 2011-10-01 01:01:08 +0000 | [diff] [blame^] | 12 | extern Object *object; |
| 13 | |
| 14 | // rdar://9744349 |
| 15 | id 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 Jahanian | 4ad5686 | 2011-06-20 20:54:42 +0000 | [diff] [blame] | 20 | } |
| John McCall | e4fe245 | 2011-10-01 01:01:08 +0000 | [diff] [blame^] | 21 | |
| 22 | // rdar://10140692 |
| 23 | CFStringRef unauditedString(void); |
| 24 | CFStringRef plusOneString(void) __attribute__((cf_returns_retained)); |
| 25 | |
| 26 | #pragma clang arc_cf_code_audited begin |
| 27 | CFStringRef auditedString(void); |
| 28 | CFStringRef auditedCreateString(void); |
| 29 | #pragma clang arc_cf_code_audited end |
| 30 | |
| 31 | void 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 | } |