Home | History | Annotate | Download | only in ARCMT
      1 // RUN: %clang_cc1 -arcmt-check -verify -triple x86_64-apple-darwin10 -fsyntax-only -fblocks -Warc-abi  %s
      2 // DISABLE: mingw32
      3 
      4 // Classes that have an Objective-C object pointer.
      5 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}}
      6   id x;
      7 };
      8 
      9 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}}
     10   id x[3];
     11 };
     12 
     13 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}}
     14   id x[3][2];
     15 };
     16 
     17 // Don't complain if the type has non-external linkage
     18 namespace {
     19   struct HasObjectMember3 {
     20     id x[3][2];
     21   };
     22 }
     23 
     24 // Don't complain if the Objective-C pointer type was explicitly given
     25 // no lifetime.
     26 struct HasObjectMember3 { 
     27   __unsafe_unretained id x[3][2];
     28 };
     29 
     30 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}}
     31   int (^bp)(int);
     32 };
     33 
     34 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}}
     35   int (^bp[2][3])(int);
     36 };
     37 
     38 struct NonPOD {
     39   NonPOD(const NonPOD&);
     40 };
     41 
     42 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}} \
     43   // expected-warning{{'HasObjectMemberAndNonPOD0' cannot be shared between ARC and non-ARC code; add a non-trivial destructor to make it ABI-compatible}}
     44   id x;
     45   NonPOD np;
     46 };
     47 
     48 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}} \
     49   // expected-warning{{'HasObjectMemberAndNonPOD1' cannot be shared between ARC and non-ARC code; add a non-trivial destructor to make it ABI-compatible}}
     50   NonPOD np;
     51   id x[3];
     52 };
     53 
     54 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}} \
     55   // expected-warning{{'HasObjectMemberAndNonPOD2' cannot be shared between ARC and non-ARC code; add a non-trivial destructor to make it ABI-compatible}}
     56   NonPOD np;
     57   id x[3][2];
     58 };
     59 
     60 struct HasObjectMemberAndNonPOD3 {
     61   HasObjectMemberAndNonPOD3 &operator=(const HasObjectMemberAndNonPOD3&);
     62   ~HasObjectMemberAndNonPOD3();
     63   NonPOD np;
     64   id x[3][2];
     65 };
     66 
     67 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}} \
     68 // expected-warning{{'HasBlockPointerMemberAndNonPOD0' cannot be shared between ARC and non-ARC code; add a non-trivial destructor to make it ABI-compatible}}
     69   NonPOD np;
     70   int (^bp)(int);
     71 };
     72 
     73 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}} \
     74 // expected-warning{{'HasBlockPointerMemberAndNonPOD1' cannot be shared between ARC and non-ARC code; add a non-trivial destructor to make it ABI-compatible}}
     75   NonPOD np;
     76   int (^bp[2][3])(int);
     77 };
     78 
     79 int check_non_pod_objc_pointer0[__is_pod(id)? 1 : -1];
     80 int check_non_pod_objc_pointer1[__is_pod(__strong id)? -1 : 1];
     81 int check_non_pod_objc_pointer2[__is_pod(__unsafe_unretained id)? 1 : -1];
     82 int check_non_pod_objc_pointer3[__is_pod(id[2][3])? 1 : -1];
     83 int check_non_pod_objc_pointer4[__is_pod(__unsafe_unretained id[2][3])? 1 : -1];
     84 int check_non_pod_block0[__is_pod(int (^)(int))? 1 : -1];
     85 int check_non_pod_block1[__is_pod(int (^ __unsafe_unretained)(int))? 1 : -1];
     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