xref: /minix3/external/bsd/llvm/dist/clang/test/SemaObjC/default-synthesize-3.m (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1f4a2713aSLionel Sambuc// RUN: %clang_cc1 -x objective-c -fsyntax-only -verify -Wno-objc-root-class %s
2f4a2713aSLionel Sambuc// RUN: %clang_cc1 -x objective-c++ -fsyntax-only -verify -Wno-objc-root-class %s
3f4a2713aSLionel Sambuc
4f4a2713aSLionel Sambuc#if __has_attribute(objc_requires_property_definitions)
5f4a2713aSLionel Sambuc__attribute ((objc_requires_property_definitions))
6f4a2713aSLionel Sambuc#endif
7f4a2713aSLionel Sambuc@interface NoAuto // expected-note 2 {{class with specified objc_requires_property_definitions attribute is declared here}}
8f4a2713aSLionel Sambuc@property int NoAutoProp; // expected-note 2 {{property declared here}}
9f4a2713aSLionel Sambuc@end
10f4a2713aSLionel Sambuc
11f4a2713aSLionel Sambuc@implementation NoAuto  // expected-warning {{property 'NoAutoProp' requires method 'NoAutoProp' to be defined}} \
12f4a2713aSLionel Sambuc                        // expected-warning {{property 'NoAutoProp' requires method 'setNoAutoProp:'}}
13f4a2713aSLionel Sambuc@end
14f4a2713aSLionel Sambuc
15f4a2713aSLionel Sambuc__attribute ((objc_requires_property_definitions))  // redundant, just for testing
16f4a2713aSLionel Sambuc@interface Sub : NoAuto  // expected-note 3 {{class with specified objc_requires_property_definitions attribute is declared here}}
17f4a2713aSLionel Sambuc@property (copy) id SubProperty; // expected-note 2 {{property declared here}}
18f4a2713aSLionel Sambuc@end
19f4a2713aSLionel Sambuc
20f4a2713aSLionel Sambuc@implementation Sub // expected-warning {{property 'SubProperty' requires method 'SubProperty' to be defined}} \
21f4a2713aSLionel Sambuc                    // expected-warning {{property 'SubProperty' requires method 'setSubProperty:' to be defined}}
22f4a2713aSLionel Sambuc@end
23f4a2713aSLionel Sambuc
24f4a2713aSLionel Sambuc@interface Deep : Sub
25f4a2713aSLionel Sambuc@property (copy) id DeepProperty;
26f4a2713aSLionel Sambuc@property (copy) id DeepSynthProperty;
27f4a2713aSLionel Sambuc@property (copy) id DeepMustSynthProperty; // expected-note {{property declared here}}
28f4a2713aSLionel Sambuc@end
29f4a2713aSLionel Sambuc
30f4a2713aSLionel Sambuc@implementation Deep // expected-warning {{property 'DeepMustSynthProperty' requires method 'setDeepMustSynthProperty:' to be defined}}
31f4a2713aSLionel Sambuc@dynamic DeepProperty;
32f4a2713aSLionel Sambuc@synthesize DeepSynthProperty;
33f4a2713aSLionel Sambuc- (id) DeepMustSynthProperty { return 0; }
34f4a2713aSLionel Sambuc@end
35f4a2713aSLionel Sambuc
36f4a2713aSLionel Sambuc__attribute ((objc_requires_property_definitions))
37f4a2713aSLionel Sambuc@interface Deep(CAT)  // expected-error {{attributes may not be specified on a category}}
38f4a2713aSLionel Sambuc@end
39f4a2713aSLionel Sambuc
40*0a6a1f1dSLionel Sambuc__attribute ((objc_requires_property_definitions)) // expected-error {{'objc_requires_property_definitions' attribute only applies to Objective-C interfaces}}
41f4a2713aSLionel Sambuc@protocol P @end
42f4a2713aSLionel Sambuc
43f4a2713aSLionel Sambuc// rdar://13388503
44f4a2713aSLionel Sambuc@interface NSObject @end
45f4a2713aSLionel Sambuc@protocol Foo
46f4a2713aSLionel Sambuc@property (readonly) char isFoo; // expected-note {{property declared here}}
47*0a6a1f1dSLionel Sambuc@property (readonly) char isNotFree;  // expected-note {{property declared here}}
48f4a2713aSLionel Sambuc@end
49f4a2713aSLionel Sambuc
50f4a2713aSLionel Sambuc@interface Bar : NSObject <Foo>
51f4a2713aSLionel Sambuc@end
52f4a2713aSLionel Sambuc
53f4a2713aSLionel Sambuc@implementation Bar
54f4a2713aSLionel Sambuc- (char)isFoo {
55f4a2713aSLionel Sambuc    return 0;
56f4a2713aSLionel Sambuc}
57f4a2713aSLionel Sambuc- (char)isNotFree {
58f4a2713aSLionel Sambuc    return 0;
59f4a2713aSLionel Sambuc}
60f4a2713aSLionel Sambuc@end
61f4a2713aSLionel Sambuc
62f4a2713aSLionel Sambuc@interface Baz : Bar
63f4a2713aSLionel Sambuc@end
64f4a2713aSLionel Sambuc
65f4a2713aSLionel Sambuc@interface Baz ()
66f4a2713aSLionel Sambuc@property (readwrite) char isFoo; // expected-warning {{auto property synthesis will not synthesize property 'isFoo' because it is 'readwrite' but it will be synthesized 'readonly' via another property}}
67f4a2713aSLionel Sambuc@property char Property1; // expected-warning {{auto property synthesis will not synthesize property 'Property1' because it cannot share an ivar with another synthesized property}}
68f4a2713aSLionel Sambuc@property char Property2;
69*0a6a1f1dSLionel Sambuc@property (readwrite) char isNotFree; // expected-warning {{auto property synthesis will not synthesize property 'isNotFree'}}
70f4a2713aSLionel Sambuc@end
71f4a2713aSLionel Sambuc
72*0a6a1f1dSLionel Sambuc@implementation Baz { // expected-note {{detected while default synthesizing properties in class implementation}}
73f4a2713aSLionel Sambuc    char _isFoo;
74f4a2713aSLionel Sambuc    char _isNotFree;
75f4a2713aSLionel Sambuc}
76f4a2713aSLionel Sambuc@synthesize Property2 = Property1; // expected-note {{property synthesized here}}
77f4a2713aSLionel Sambuc
78f4a2713aSLionel Sambuc- (void) setIsNotFree : (char)Arg {
79f4a2713aSLionel Sambuc  _isNotFree = Arg;
80f4a2713aSLionel Sambuc}
81f4a2713aSLionel Sambuc
82f4a2713aSLionel Sambuc@end
83f4a2713aSLionel Sambuc
84f4a2713aSLionel Sambuc// More test where such warnings should not be issued.
85f4a2713aSLionel Sambuc@protocol MyProtocol
86f4a2713aSLionel Sambuc-(void)setProp1:(id)x;
87f4a2713aSLionel Sambuc@end
88f4a2713aSLionel Sambuc
89f4a2713aSLionel Sambuc@protocol P1 <MyProtocol>
90f4a2713aSLionel Sambuc@end
91f4a2713aSLionel Sambuc
92f4a2713aSLionel Sambuc@interface B
93*0a6a1f1dSLionel Sambuc@property (readonly) id prop;  // expected-note {{property declared here}}
94*0a6a1f1dSLionel Sambuc@property (readonly) id prop1;  // expected-note {{property declared here}}
95*0a6a1f1dSLionel Sambuc@property (readonly) id prop2;  // expected-note {{property declared here}}
96f4a2713aSLionel Sambuc@end
97f4a2713aSLionel Sambuc
98f4a2713aSLionel Sambuc@interface B()
99f4a2713aSLionel Sambuc-(void)setProp:(id)x;
100f4a2713aSLionel Sambuc@end
101f4a2713aSLionel Sambuc
102f4a2713aSLionel Sambuc@interface B(cat)
103f4a2713aSLionel Sambuc@property (readwrite) id prop2;
104f4a2713aSLionel Sambuc@end
105f4a2713aSLionel Sambuc
106f4a2713aSLionel Sambuc@interface S : B<P1>
107*0a6a1f1dSLionel Sambuc@property (assign,readwrite) id prop; // expected-warning {{auto property synthesis will not synthesize property 'prop'}}
108*0a6a1f1dSLionel Sambuc@property (assign,readwrite) id prop1; // expected-warning {{auto property synthesis will not synthesize property 'prop1'}}
109*0a6a1f1dSLionel Sambuc@property (assign,readwrite) id prop2; // expected-warning {{auto property synthesis will not synthesize property 'prop2'}}
110f4a2713aSLionel Sambuc@end
111f4a2713aSLionel Sambuc
112*0a6a1f1dSLionel Sambuc@implementation S // expected-note 3 {{detected while default synthesizing properties in class implementation}}
113f4a2713aSLionel Sambuc@end
114f4a2713aSLionel Sambuc
115f4a2713aSLionel Sambuc// rdar://14085456
116f4a2713aSLionel Sambuc// No warning must be issued in this test.
117f4a2713aSLionel Sambuc@interface ParentObject
118f4a2713aSLionel Sambuc@end
119f4a2713aSLionel Sambuc
120f4a2713aSLionel Sambuc@protocol TestObject
121f4a2713aSLionel Sambuc@property (readonly) int six;
122f4a2713aSLionel Sambuc@end
123f4a2713aSLionel Sambuc
124f4a2713aSLionel Sambuc@interface TestObject : ParentObject <TestObject>
125f4a2713aSLionel Sambuc@property int six;
126f4a2713aSLionel Sambuc@end
127f4a2713aSLionel Sambuc
128f4a2713aSLionel Sambuc@implementation TestObject
129f4a2713aSLionel Sambuc@synthesize six;
130f4a2713aSLionel Sambuc@end
131f4a2713aSLionel Sambuc
132f4a2713aSLionel Sambuc// rdar://14094682
133f4a2713aSLionel Sambuc// no warning in this test
134f4a2713aSLionel Sambuc@interface ISAChallenge : NSObject {
135f4a2713aSLionel Sambuc}
136f4a2713aSLionel Sambuc
137f4a2713aSLionel Sambuc@property (assign, readonly) int failureCount;
138f4a2713aSLionel Sambuc@end
139f4a2713aSLionel Sambuc
140f4a2713aSLionel Sambuc@interface ISSAChallenge : ISAChallenge {
141f4a2713aSLionel Sambuc    int _failureCount;
142f4a2713aSLionel Sambuc}
143f4a2713aSLionel Sambuc@property (assign, readwrite) int failureCount;
144f4a2713aSLionel Sambuc@end
145f4a2713aSLionel Sambuc
146f4a2713aSLionel Sambuc@implementation ISAChallenge
147f4a2713aSLionel Sambuc- (int)failureCount {
148f4a2713aSLionel Sambuc    return 0;
149f4a2713aSLionel Sambuc}
150f4a2713aSLionel Sambuc@end
151f4a2713aSLionel Sambuc
152f4a2713aSLionel Sambuc@implementation ISSAChallenge
153f4a2713aSLionel Sambuc
154f4a2713aSLionel Sambuc@synthesize failureCount = _failureCount;
155f4a2713aSLionel Sambuc@end
156f4a2713aSLionel Sambuc
157f4a2713aSLionel Sambuc__attribute ((objc_requires_property_definitions(1))) // expected-error {{'objc_requires_property_definitions' attribute takes no arguments}}
158f4a2713aSLionel Sambuc@interface I1
159f4a2713aSLionel Sambuc@end
160f4a2713aSLionel Sambuc
161f4a2713aSLionel Sambuc// rdar://15051465
162f4a2713aSLionel Sambuc@protocol SubFooling
163f4a2713aSLionel Sambuc  @property(nonatomic, readonly) id hoho; // expected-note 2 {{property declared here}}
164f4a2713aSLionel Sambuc@end
165f4a2713aSLionel Sambuc
166f4a2713aSLionel Sambuc@protocol Fooing<SubFooling>
167f4a2713aSLionel Sambuc  @property(nonatomic, readonly) id muahahaha; // expected-note 2 {{property declared here}}
168f4a2713aSLionel Sambuc@end
169f4a2713aSLionel Sambuc
170f4a2713aSLionel Sambuctypedef NSObject<Fooing> FooObject;
171f4a2713aSLionel Sambuc
172f4a2713aSLionel Sambuc@interface Okay : NSObject<Fooing>
173f4a2713aSLionel Sambuc@end
174f4a2713aSLionel Sambuc
175*0a6a1f1dSLionel Sambuc@implementation Okay // expected-warning {{auto property synthesis will not synthesize property 'muahahaha' declared in protocol 'Fooing'}} expected-warning {{auto property synthesis will not synthesize property 'hoho' declared in protocol 'SubFooling'}}
176f4a2713aSLionel Sambuc@end
177f4a2713aSLionel Sambuc
178f4a2713aSLionel Sambuc@interface Fail : FooObject
179f4a2713aSLionel Sambuc@end
180f4a2713aSLionel Sambuc
181*0a6a1f1dSLionel Sambuc@implementation Fail // expected-warning {{auto property synthesis will not synthesize property 'muahahaha' declared in protocol 'Fooing'}} expected-warning {{auto property synthesis will not synthesize property 'hoho' declared in protocol 'SubFooling'}}
182f4a2713aSLionel Sambuc@end
183f4a2713aSLionel Sambuc
184*0a6a1f1dSLionel Sambuc// rdar://16089191
185*0a6a1f1dSLionel Sambuc@class NSURL;
186*0a6a1f1dSLionel Sambuc
187*0a6a1f1dSLionel Sambuc@interface Root
188*0a6a1f1dSLionel Sambuc- (void)setFileURL : (NSURL *) arg;
189*0a6a1f1dSLionel Sambuc- (void)setFile : (NSURL *) arg;
190*0a6a1f1dSLionel Sambuc- (NSURL *)fileSys;
191*0a6a1f1dSLionel Sambuc- (void)setFileSys : (NSURL *) arg;
192*0a6a1f1dSLionel Sambuc- (NSURL *)fileKerl;
193*0a6a1f1dSLionel Sambuc@end
194*0a6a1f1dSLionel Sambuc
195*0a6a1f1dSLionel Sambuc@interface SuperClass : Root
196*0a6a1f1dSLionel Sambuc- (NSURL *)fileURL;
197*0a6a1f1dSLionel Sambuc- (NSURL *)file;
198*0a6a1f1dSLionel Sambuc- (NSURL *)fileLog;
199*0a6a1f1dSLionel Sambuc- (void)setFileLog : (NSURL *) arg;
200*0a6a1f1dSLionel Sambuc- (void)setFileKerl : (NSURL *) arg;
201*0a6a1f1dSLionel Sambuc@end
202*0a6a1f1dSLionel Sambuc
203*0a6a1f1dSLionel Sambuc@protocol r16089191Protocol
204*0a6a1f1dSLionel Sambuc@property (readonly) NSURL *fileURL;
205*0a6a1f1dSLionel Sambuc@property (copy) NSURL *file;
206*0a6a1f1dSLionel Sambuc@property (copy) NSURL *fileSys;
207*0a6a1f1dSLionel Sambuc@property (copy) NSURL *fileLog;
208*0a6a1f1dSLionel Sambuc@property (copy) NSURL *fileKerl;
209*0a6a1f1dSLionel Sambuc@end
210*0a6a1f1dSLionel Sambuc
211*0a6a1f1dSLionel Sambuc@interface SubClass : SuperClass <r16089191Protocol>
212*0a6a1f1dSLionel Sambuc@end
213*0a6a1f1dSLionel Sambuc
214*0a6a1f1dSLionel Sambuc@implementation SubClass
215*0a6a1f1dSLionel Sambuc@end
216