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