blob: 1c5cf7af3a18054de001176bb01ac86b66c48a95 [file] [log] [blame]
John McCalld1e40d52011-10-02 01:16:38 +00001// RUN: %clang_cc1 -fsyntax-only -fobjc-arc -Warc-abi -verify -fblocks -triple x86_64-apple-darwin10.0.0 %s
John McCallf85e1932011-06-15 23:02:42 +00002
3// Classes that have an Objective-C object pointer.
4struct 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
8struct 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
12struct 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
17namespace {
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 Kyrtzidisb8b03132011-06-24 00:08:59 +000024// no ownership.
John McCallf85e1932011-06-15 23:02:42 +000025struct HasObjectMember3 {
26 __unsafe_unretained id x[3][2];
27};
28
29struct 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
33struct 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
37struct NonPOD {
38 NonPOD(const NonPOD&);
39};
40
41struct 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
47struct 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
53struct 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
59struct HasObjectMemberAndNonPOD3 {
60 HasObjectMemberAndNonPOD3 &operator=(const HasObjectMemberAndNonPOD3&);
61 ~HasObjectMemberAndNonPOD3();
62 NonPOD np;
63 id x[3][2];
64};
65
66struct 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
72struct 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 Gregorf96e9042011-07-12 17:28:52 +000078int check_non_pod_objc_pointer0[__is_pod(id)? 1 : -1];
John McCallf85e1932011-06-15 23:02:42 +000079int check_non_pod_objc_pointer1[__is_pod(__strong id)? -1 : 1];
80int check_non_pod_objc_pointer2[__is_pod(__unsafe_unretained id)? 1 : -1];
Douglas Gregorf96e9042011-07-12 17:28:52 +000081int check_non_pod_objc_pointer3[__is_pod(id[2][3])? 1 : -1];
John McCallf85e1932011-06-15 23:02:42 +000082int check_non_pod_objc_pointer4[__is_pod(__unsafe_unretained id[2][3])? 1 : -1];
Douglas Gregorf96e9042011-07-12 17:28:52 +000083int check_non_pod_block0[__is_pod(int (^)(int))? 1 : -1];
John McCallf85e1932011-06-15 23:02:42 +000084int check_non_pod_block1[__is_pod(int (^ __unsafe_unretained)(int))? 1 : -1];
Douglas Gregorf96e9042011-07-12 17:28:52 +000085int check_non_pod_block2[__is_pod(int (^ __strong)(int))? -1 : 1];
John McCallf85e1932011-06-15 23:02:42 +000086
87struct FlexibleArrayMember0 {
88 int length;
89 id array[]; // expected-error{{flexible array member 'array' of non-POD element type 'id __strong[]'}}
90};
91
92struct FlexibleArrayMember1 {
93 int length;
94 __unsafe_unretained id array[];
95};
96
97// It's okay to pass a retainable type through an ellipsis.
98void variadic(...);
99void test_variadic() {
100 variadic(1, 17, @"Foo");
101}
102
103// It's okay to create a VLA of retainable types.
104void vla(int n) {
105 id vla[n];
106}
107
108@interface Crufty {
109 union {
110 struct {
Argyrios Kyrtzidisb8b03132011-06-24 00:08:59 +0000111 id object; // expected-note{{has __strong ownership}}
John McCallf85e1932011-06-15 23:02:42 +0000112 } an_object; // expected-error{{union member 'an_object' has a non-trivial copy constructor}}
113 void *ptr;
114 } storage;
115}
116@end