John McCall | d1e40d5 | 2011-10-02 01:16:38 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -fobjc-arc -Warc-abi -verify -fblocks -triple x86_64-apple-darwin10.0.0 %s |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 2 | |
| 3 | // Classes that have an Objective-C object pointer. |
| 4 | struct HasObjectMember0 { // expected-warning{{'HasObjectMember0' cannot be shared between ARC and non-ARC code; add a copy constructor, a copy assignment operator, and a destructor to make it ABI-compatible}} |
| 5 | id x; |
| 6 | }; |
| 7 | |
| 8 | struct HasObjectMember1 { // expected-warning{{'HasObjectMember1' cannot be shared between ARC and non-ARC code; add a copy constructor, a copy assignment operator, and a destructor to make it ABI-compatible}} |
| 9 | id x[3]; |
| 10 | }; |
| 11 | |
| 12 | struct HasObjectMember2 { // expected-warning{{'HasObjectMember2' cannot be shared between ARC and non-ARC code; add a copy constructor, a copy assignment operator, and a destructor to make it ABI-compatible}} |
| 13 | id x[3][2]; |
| 14 | }; |
| 15 | |
| 16 | // Don't complain if the type has non-external linkage |
| 17 | namespace { |
| 18 | struct HasObjectMember3 { |
| 19 | id x[3][2]; |
| 20 | }; |
| 21 | } |
| 22 | |
| 23 | // Don't complain if the Objective-C pointer type was explicitly given |
Argyrios Kyrtzidis | b8b0313 | 2011-06-24 00:08:59 +0000 | [diff] [blame] | 24 | // no ownership. |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 25 | struct HasObjectMember3 { |
| 26 | __unsafe_unretained id x[3][2]; |
| 27 | }; |
| 28 | |
| 29 | struct HasBlockPointerMember0 { // expected-warning{{'HasBlockPointerMember0' cannot be shared between ARC and non-ARC code; add a copy constructor, a copy assignment operator, and a destructor to make it ABI-compatible}} |
| 30 | int (^bp)(int); |
| 31 | }; |
| 32 | |
| 33 | struct HasBlockPointerMember1 { // expected-warning{{'HasBlockPointerMember1' cannot be shared between ARC and non-ARC code; add a copy constructor, a copy assignment operator, and a destructor to make it ABI-compatible}} |
| 34 | int (^bp[2][3])(int); |
| 35 | }; |
| 36 | |
| 37 | struct NonPOD { |
| 38 | NonPOD(const NonPOD&); |
| 39 | }; |
| 40 | |
| 41 | struct HasObjectMemberAndNonPOD0 { // expected-warning{{'HasObjectMemberAndNonPOD0' cannot be shared between ARC and non-ARC code; add a non-trivial copy assignment operator to make it ABI-compatible}} \ |
| 42 | // expected-warning{{'HasObjectMemberAndNonPOD0' cannot be shared between ARC and non-ARC code; add a non-trivial destructor to make it ABI-compatible}} |
| 43 | id x; |
| 44 | NonPOD np; |
| 45 | }; |
| 46 | |
| 47 | struct HasObjectMemberAndNonPOD1 { // expected-warning{{'HasObjectMemberAndNonPOD1' cannot be shared between ARC and non-ARC code; add a non-trivial copy assignment operator to make it ABI-compatible}} \ |
| 48 | // expected-warning{{'HasObjectMemberAndNonPOD1' cannot be shared between ARC and non-ARC code; add a non-trivial destructor to make it ABI-compatible}} |
| 49 | NonPOD np; |
| 50 | id x[3]; |
| 51 | }; |
| 52 | |
| 53 | struct HasObjectMemberAndNonPOD2 { // expected-warning{{'HasObjectMemberAndNonPOD2' cannot be shared between ARC and non-ARC code; add a non-trivial copy assignment operator to make it ABI-compatible}} \ |
| 54 | // expected-warning{{'HasObjectMemberAndNonPOD2' cannot be shared between ARC and non-ARC code; add a non-trivial destructor to make it ABI-compatible}} |
| 55 | NonPOD np; |
| 56 | id x[3][2]; |
| 57 | }; |
| 58 | |
| 59 | struct HasObjectMemberAndNonPOD3 { |
| 60 | HasObjectMemberAndNonPOD3 &operator=(const HasObjectMemberAndNonPOD3&); |
| 61 | ~HasObjectMemberAndNonPOD3(); |
| 62 | NonPOD np; |
| 63 | id x[3][2]; |
| 64 | }; |
| 65 | |
| 66 | struct HasBlockPointerMemberAndNonPOD0 { // expected-warning{{'HasBlockPointerMemberAndNonPOD0' cannot be shared between ARC and non-ARC code; add a non-trivial copy assignment operator to make it ABI-compatible}} \ |
| 67 | // expected-warning{{'HasBlockPointerMemberAndNonPOD0' cannot be shared between ARC and non-ARC code; add a non-trivial destructor to make it ABI-compatible}} |
| 68 | NonPOD np; |
| 69 | int (^bp)(int); |
| 70 | }; |
| 71 | |
| 72 | struct HasBlockPointerMemberAndNonPOD1 { // expected-warning{{'HasBlockPointerMemberAndNonPOD1' cannot be shared between ARC and non-ARC code; add a non-trivial copy assignment operator to make it ABI-compatible}} \ |
| 73 | // expected-warning{{'HasBlockPointerMemberAndNonPOD1' cannot be shared between ARC and non-ARC code; add a non-trivial destructor to make it ABI-compatible}} |
| 74 | NonPOD np; |
| 75 | int (^bp[2][3])(int); |
| 76 | }; |
| 77 | |
Douglas Gregor | f96e904 | 2011-07-12 17:28:52 +0000 | [diff] [blame] | 78 | int check_non_pod_objc_pointer0[__is_pod(id)? 1 : -1]; |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 79 | int check_non_pod_objc_pointer1[__is_pod(__strong id)? -1 : 1]; |
| 80 | int check_non_pod_objc_pointer2[__is_pod(__unsafe_unretained id)? 1 : -1]; |
Douglas Gregor | f96e904 | 2011-07-12 17:28:52 +0000 | [diff] [blame] | 81 | int check_non_pod_objc_pointer3[__is_pod(id[2][3])? 1 : -1]; |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 82 | int check_non_pod_objc_pointer4[__is_pod(__unsafe_unretained id[2][3])? 1 : -1]; |
Douglas Gregor | f96e904 | 2011-07-12 17:28:52 +0000 | [diff] [blame] | 83 | int check_non_pod_block0[__is_pod(int (^)(int))? 1 : -1]; |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 84 | int check_non_pod_block1[__is_pod(int (^ __unsafe_unretained)(int))? 1 : -1]; |
Douglas Gregor | f96e904 | 2011-07-12 17:28:52 +0000 | [diff] [blame] | 85 | int check_non_pod_block2[__is_pod(int (^ __strong)(int))? -1 : 1]; |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 86 | |
| 87 | struct FlexibleArrayMember0 { |
| 88 | int length; |
| 89 | id array[]; // expected-error{{flexible array member 'array' of non-POD element type 'id __strong[]'}} |
| 90 | }; |
| 91 | |
| 92 | struct FlexibleArrayMember1 { |
| 93 | int length; |
| 94 | __unsafe_unretained id array[]; |
| 95 | }; |
| 96 | |
| 97 | // It's okay to pass a retainable type through an ellipsis. |
| 98 | void variadic(...); |
| 99 | void test_variadic() { |
| 100 | variadic(1, 17, @"Foo"); |
| 101 | } |
| 102 | |
| 103 | // It's okay to create a VLA of retainable types. |
| 104 | void vla(int n) { |
| 105 | id vla[n]; |
| 106 | } |
| 107 | |
| 108 | @interface Crufty { |
| 109 | union { |
| 110 | struct { |
Argyrios Kyrtzidis | b8b0313 | 2011-06-24 00:08:59 +0000 | [diff] [blame] | 111 | id object; // expected-note{{has __strong ownership}} |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 112 | } an_object; // expected-error{{union member 'an_object' has a non-trivial copy constructor}} |
| 113 | void *ptr; |
| 114 | } storage; |
| 115 | } |
| 116 | @end |