John McCall | 9f084a3 | 2011-07-06 00:26:06 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fobjc-nonfragile-abi -fobjc-runtime-has-weak -fsyntax-only -fobjc-arc -verify -Warc-abi -fblocks -triple x86_64-apple-darwin10.0.0 %s |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 2 | |
| 3 | typedef __strong id strong_id; |
| 4 | typedef __weak id weak_id; |
| 5 | void test_pseudo_destructors(__strong id *sptr, __weak id *wptr) { |
| 6 | sptr->~id(); // okay |
| 7 | wptr->~id(); // okay |
| 8 | sptr->~strong_id(); // okay |
| 9 | wptr->~weak_id(); |
| 10 | sptr->~weak_id(); // expected-error{{pseudo-destructor destroys object of type '__strong id' with inconsistently-qualified type 'weak_id' (aka '__weak id')}} |
| 11 | wptr->strong_id::~strong_id(); // expected-error{{pseudo-destructor destroys object of type '__weak id' with inconsistently-qualified type 'strong_id' (aka '__strong id')}} |
| 12 | |
| 13 | sptr->id::~id(); // okay |
| 14 | wptr->id::~id(); // okay |
| 15 | } |
| 16 | |
| 17 | void test_delete(__strong id *sptr, __weak id *wptr) { |
| 18 | delete sptr; |
| 19 | delete wptr; |
| 20 | delete [] sptr; // expected-warning{{destroying an array of '__strong id'; this array must not have been allocated from non-ARC code}} |
| 21 | delete [] wptr; // expected-warning{{destroying an array of '__weak id'; this array must not have been allocated from non-ARC code}} |
| 22 | } |
| 23 | |
| 24 | void test_new(int n) { |
| 25 | (void)new strong_id; |
| 26 | (void)new weak_id; |
| 27 | (void)new strong_id [n]; // expected-warning{{allocating an array of 'strong_id' (aka '__strong id'); this array must not be deleted in non-ARC code}} |
| 28 | (void)new weak_id [n]; // expected-warning{{allocating an array of 'weak_id' (aka '__weak id'); this array must not be deleted in non-ARC code}} |
| 29 | |
| 30 | (void)new __strong id; |
| 31 | (void)new __weak id; |
| 32 | (void)new __strong id [n]; // expected-warning{{allocating an array of '__strong id'; this array must not be deleted in non-ARC code}} |
| 33 | |
| 34 | // Infer '__strong'. |
| 35 | __strong id *idptr = new id; |
| 36 | __strong id *idptr2 = new id [n]; // expected-warning{{allocating an array of '__strong id'; this array must not be deleted in non-ARC code}} |
| 37 | |
| 38 | // ... but not for arrays. |
| 39 | typedef id id_array[2][3]; |
Argyrios Kyrtzidis | b8b0313 | 2011-06-24 00:08:59 +0000 | [diff] [blame] | 40 | (void)new id_array; // expected-error{{'new' cannot allocate an array of 'id' with no explicit ownership}} |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 41 | |
| 42 | typedef __strong id strong_id_array[2][3]; |
| 43 | typedef __strong id strong_id_3[3]; |
| 44 | strong_id_3 *idptr3 = new strong_id_array; // expected-warning{{allocating an array of '__strong id'; this array must not be deleted in non-ARC code}} |
| 45 | } |
| 46 | |
| 47 | void test_jump_scope() { |
| 48 | goto done; // expected-error{{goto into protected scope}} |
| 49 | __strong id x; // expected-note{{jump bypasses initialization of retaining variable}} |
| 50 | done: |
| 51 | return; |
| 52 | } |