Home | History | Annotate | Download | only in SemaObjCXX
      1 // RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s
      2 // rdar: //8550657
      3 
      4 @interface NSArray @end
      5 
      6 @interface NSMutableArray : NSArray @end
      7 
      8 @interface MyClass
      9 {
     10   NSMutableArray * _array;
     11 }
     12 
     13 @property (readonly) NSMutableArray * array;
     14 
     15 @end
     16 
     17 @interface MyClass ()
     18 
     19 @property (readwrite, retain) NSMutableArray * array;
     20 
     21 @end
     22 
     23 @implementation MyClass
     24 
     25 @synthesize array=_array;
     26 
     27 @end
     28 
     29 int main(void)
     30 {
     31   return 0;
     32 }
     33 
     34 // rdar://6137845
     35 class TCPPObject
     36 {
     37 public:
     38  TCPPObject(const TCPPObject& inObj);
     39  TCPPObject();
     40  ~TCPPObject();
     41  TCPPObject& operator=(const TCPPObject& inObj); // expected-note {{'operator=' declared here}}
     42 private:
     43  void* fData;
     44 };
     45 
     46 class Trivial
     47 {
     48 public:
     49  Trivial(const Trivial& inObj);
     50  Trivial();
     51  ~Trivial();
     52 private:
     53  void* fData;
     54 };
     55 
     56 @interface MyDocument
     57 {
     58 @private
     59  TCPPObject _cppObject;
     60  TCPPObject _ncppObject;
     61  Trivial _tcppObject;
     62 }
     63 @property (assign, readwrite) const TCPPObject& cppObject;
     64 @property (assign, readwrite, nonatomic) const TCPPObject& ncppObject;
     65 @property (assign, readwrite) const Trivial& tcppObject;
     66 @end
     67 
     68 @implementation MyDocument
     69 
     70 @synthesize cppObject = _cppObject; // expected-error {{atomic property of reference type 'const TCPPObject &' cannot have non-trivial assignment operator}}
     71 @synthesize ncppObject = _ncppObject;
     72 
     73 @synthesize tcppObject = _tcppObject;
     74 @end
     75 
     76 struct IncompleteStruct; // expected-note 2 {{forward declaration of 'IncompleteStruct'}}
     77 struct ConvertToIncomplete { operator IncompleteStruct&(); };
     78 @interface SynthIncompleteRef
     79 @property (readonly, nonatomic) IncompleteStruct& x; // expected-note {{property declared here}}
     80 @property (readonly, nonatomic) IncompleteStruct& y; // expected-note {{property declared here}}
     81 @end
     82 
     83 @implementation SynthIncompleteRef // expected-error {{cannot synthesize property 'x' with incomplete type 'IncompleteStruct'}}
     84 @synthesize y; // expected-error {{cannot synthesize property 'y' with incomplete type 'IncompleteStruct'}}
     85 @end 
     86 
     87 
     88 // Check error handling for instantiation during property synthesis.
     89 template<typename T> class TemplateClass1 {
     90   T *x; // expected-error {{'x' declared as a pointer to a reference of type 'int &'}}
     91 };
     92 template<typename T> class TemplateClass2 {
     93   TemplateClass2& operator=(TemplateClass1<T>);
     94   TemplateClass2& operator=(TemplateClass2) { T(); } // expected-error {{reference to type 'int' requires an initializer}} \
     95                                                      // expected-note 2 {{implicitly declared private here}} \
     96                                                      // expected-note {{'operator=' declared here}}
     97 };
     98 __attribute__((objc_root_class)) @interface InterfaceWithTemplateProperties 
     99 @property TemplateClass2<int&> intprop;
    100 @property TemplateClass2<int&> &floatprop;
    101 @end
    102 @implementation InterfaceWithTemplateProperties // expected-error 2 {{'operator=' is a private member of 'TemplateClass2<int &>'}} \
    103 																								// expected-error {{atomic property of reference type 'TemplateClass2<int &> &' cannot have non-trivial assignment operator}} \
    104 																								// expected-note {{in instantiation of template class}} \
    105 																								// expected-note {{in instantiation of member function}}
    106 @end  
    107