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