[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / SemaObjCXX / property-synthesis-error.mm
blob0982c81284a84b84706beae8c4a2d2ee9dd3aacc
1 // RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s
3 @interface NSArray @end
5 @interface NSMutableArray : NSArray @end
7 @interface MyClass
9   NSMutableArray * _array;
12 @property (readonly) NSMutableArray * array;
14 @end
16 @interface MyClass ()
18 @property (readwrite, retain) NSMutableArray * array;
20 @end
22 @implementation MyClass
24 @synthesize array=_array;
26 @end
28 int main(void)
30   return 0;
33 class TCPPObject
35 public:
36  TCPPObject(const TCPPObject& inObj);
37  TCPPObject();
38  ~TCPPObject();
39  TCPPObject& operator=(const TCPPObject& inObj); // expected-note {{'operator=' declared here}}
40 private:
41  void* fData;
44 class Trivial
46 public:
47  Trivial(const Trivial& inObj);
48  Trivial();
49  ~Trivial();
50 private:
51  void* fData;
54 @interface MyDocument
56 @private
57  TCPPObject _cppObject;
58  TCPPObject _ncppObject;
59  Trivial _tcppObject;
61 @property (assign, readwrite) const TCPPObject& cppObject;
62 @property (assign, readwrite, nonatomic) const TCPPObject& ncppObject;
63 @property (assign, readwrite) const Trivial& tcppObject;
64 @end
66 @implementation MyDocument
68 @synthesize cppObject = _cppObject; // expected-error {{atomic property of reference type 'const TCPPObject &' cannot have non-trivial assignment operator}}
69 @synthesize ncppObject = _ncppObject;
71 @synthesize tcppObject = _tcppObject;
72 @end
74 struct IncompleteStruct; // expected-note 2 {{forward declaration of 'IncompleteStruct'}}
75 struct ConvertToIncomplete { operator IncompleteStruct&(); };
76 @interface SynthIncompleteRef
77 @property (readonly, nonatomic) IncompleteStruct& x; // expected-note {{property declared here}}
78 @property (readonly, nonatomic) IncompleteStruct& y; // expected-note {{property declared here}}
79 @end
81 @implementation SynthIncompleteRef // expected-error {{cannot synthesize property 'x' with incomplete type 'IncompleteStruct'}}
82 @synthesize y; // expected-error {{cannot synthesize property 'y' with incomplete type 'IncompleteStruct'}}
83 @end 
86 // Check error handling for instantiation during property synthesis.
87 template<typename T> class TemplateClass1 {
88   T *x; // expected-error {{'x' declared as a pointer to a reference of type 'int &'}}
90 template<typename T> class TemplateClass2 {
91   TemplateClass2& operator=(TemplateClass1<T>);
92   TemplateClass2& operator=(TemplateClass2) { T(); } // expected-error {{reference to type 'int' requires an initializer}} \
93                                                      // expected-note 2 {{implicitly declared private here}} \
94                                                      // expected-note {{'operator=' declared here}}
96 __attribute__((objc_root_class)) @interface InterfaceWithTemplateProperties 
97 @property TemplateClass2<int&> intprop;
98 @property TemplateClass2<int&> &floatprop;
99 @end
100 @implementation InterfaceWithTemplateProperties // expected-error 2 {{'operator=' is a private member of 'TemplateClass2<int &>'}} \
101                                                                                                                                                                                                 // expected-error {{atomic property of reference type 'TemplateClass2<int &> &' cannot have non-trivial assignment operator}} \
102                                                                                                                                                                                                 // expected-note {{in instantiation of template class}} \
103                                                                                                                                                                                                 // expected-note {{in instantiation of member function}}
104 @end