blob: 1c32665a2dd75673eae9e7cd714356154d3e3078 [file] [log] [blame]
Rafael Espindola14f98892013-09-27 20:21:48 +00001// RUN: %clang_cc1 -x objective-c -fsyntax-only -verify -Wno-objc-root-class %s
2// RUN: %clang_cc1 -x objective-c++ -fsyntax-only -verify -Wno-objc-root-class %s
Fariborz Jahanianeb4f2c52012-01-03 19:46:00 +00003
Ted Kremenek71207fc2012-01-05 22:47:47 +00004#if __has_attribute(objc_requires_property_definitions)
5__attribute ((objc_requires_property_definitions))
Fariborz Jahanianfe40bf82012-01-04 22:29:28 +00006#endif
Ted Kremenek71207fc2012-01-05 22:47:47 +00007@interface NoAuto // expected-note 2 {{class with specified objc_requires_property_definitions attribute is declared here}}
Fariborz Jahanianeb4f2c52012-01-03 19:46:00 +00008@property int NoAutoProp; // expected-note 2 {{property declared here}}
9@end
10
11@implementation NoAuto // expected-warning {{property 'NoAutoProp' requires method 'NoAutoProp' to be defined}} \
12 // expected-warning {{property 'NoAutoProp' requires method 'setNoAutoProp:'}}
13@end
14
Ted Kremenek71207fc2012-01-05 22:47:47 +000015__attribute ((objc_requires_property_definitions)) // redundant, just for testing
16@interface Sub : NoAuto // expected-note 3 {{class with specified objc_requires_property_definitions attribute is declared here}}
Fariborz Jahanianeb4f2c52012-01-03 19:46:00 +000017@property (copy) id SubProperty; // expected-note 2 {{property declared here}}
18@end
19
20@implementation Sub // expected-warning {{property 'SubProperty' requires method 'SubProperty' to be defined}} \
21 // expected-warning {{property 'SubProperty' requires method 'setSubProperty:' to be defined}}
22@end
23
24@interface Deep : Sub
25@property (copy) id DeepProperty;
26@property (copy) id DeepSynthProperty;
27@property (copy) id DeepMustSynthProperty; // expected-note {{property declared here}}
28@end
29
30@implementation Deep // expected-warning {{property 'DeepMustSynthProperty' requires method 'setDeepMustSynthProperty:' to be defined}}
31@dynamic DeepProperty;
32@synthesize DeepSynthProperty;
33- (id) DeepMustSynthProperty { return 0; }
34@end
35
Ted Kremenek71207fc2012-01-05 22:47:47 +000036__attribute ((objc_requires_property_definitions))
Fariborz Jahanian341b8be2012-01-03 22:52:32 +000037@interface Deep(CAT) // expected-error {{attributes may not be specified on a category}}
38@end
39
Ted Kremenek71207fc2012-01-05 22:47:47 +000040__attribute ((objc_requires_property_definitions)) // expected-error {{objc_requires_property_definitions attribute may only be specified on a class}}
Fariborz Jahanian341b8be2012-01-03 22:52:32 +000041@protocol P @end
Fariborz Jahanian6114a3c2013-03-12 19:46:17 +000042
43// rdar://13388503
44@interface NSObject @end
45@protocol Foo
46@property (readonly) char isFoo; // expected-note {{property declared here}}
Fariborz Jahanian1d0d2fe2013-03-12 22:22:38 +000047@property (readonly) char isNotFree;
Fariborz Jahanian6114a3c2013-03-12 19:46:17 +000048@end
49
50@interface Bar : NSObject <Foo>
51@end
52
53@implementation Bar
54- (char)isFoo {
55 return 0;
56}
Fariborz Jahanian1d0d2fe2013-03-12 22:22:38 +000057- (char)isNotFree {
58 return 0;
59}
Fariborz Jahanian6114a3c2013-03-12 19:46:17 +000060@end
61
62@interface Baz : Bar
63@end
64
65@interface Baz ()
66@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@property char Property1; // expected-warning {{auto property synthesis will not synthesize property 'Property1' because it cannot share an ivar with another synthesized property}}
68@property char Property2;
Fariborz Jahanian1d0d2fe2013-03-12 22:22:38 +000069@property (readwrite) char isNotFree;
Fariborz Jahanian6114a3c2013-03-12 19:46:17 +000070@end
71
72@implementation Baz {
73 char _isFoo;
Fariborz Jahanian1d0d2fe2013-03-12 22:22:38 +000074 char _isNotFree;
Fariborz Jahanian6114a3c2013-03-12 19:46:17 +000075}
76@synthesize Property2 = Property1; // expected-note {{property synthesized here}}
Fariborz Jahanian1d0d2fe2013-03-12 22:22:38 +000077
78- (void) setIsNotFree : (char)Arg {
79 _isNotFree = Arg;
80}
81
Fariborz Jahanian6114a3c2013-03-12 19:46:17 +000082@end
Fariborz Jahanian5bdaef52013-03-21 20:50:53 +000083
84// More test where such warnings should not be issued.
85@protocol MyProtocol
86-(void)setProp1:(id)x;
87@end
88
89@protocol P1 <MyProtocol>
90@end
91
92@interface B
93@property (readonly) id prop;
94@property (readonly) id prop1;
95@property (readonly) id prop2;
96@end
97
98@interface B()
99-(void)setProp:(id)x;
100@end
101
102@interface B(cat)
103@property (readwrite) id prop2;
104@end
105
106@interface S : B<P1>
107@property (assign,readwrite) id prop;
108@property (assign,readwrite) id prop1;
109@property (assign,readwrite) id prop2;
110@end
111
112@implementation S
113@end
Fariborz Jahaniana6ba40c2013-06-07 18:32:55 +0000114
115// rdar://14085456
116// No warning must be issued in this test.
117@interface ParentObject
118@end
119
120@protocol TestObject
121@property (readonly) int six;
122@end
123
124@interface TestObject : ParentObject <TestObject>
125@property int six;
126@end
127
128@implementation TestObject
129@synthesize six;
130@end
131
Fariborz Jahanian6071af92013-06-07 20:26:51 +0000132// rdar://14094682
133// no warning in this test
134@interface ISAChallenge : NSObject {
135}
136
137@property (assign, readonly) int failureCount;
138@end
139
140@interface ISSAChallenge : ISAChallenge {
141 int _failureCount;
142}
143@property (assign, readwrite) int failureCount;
144@end
145
146@implementation ISAChallenge
147- (int)failureCount {
148 return 0;
149}
150@end
151
152@implementation ISSAChallenge
153
154@synthesize failureCount = _failureCount;
155@end
156
Aaron Ballmanbaec7782013-07-23 19:30:11 +0000157__attribute ((objc_requires_property_definitions(1))) // expected-error {{'objc_requires_property_definitions' attribute takes no arguments}}
Aaron Ballmanfaf71a82013-07-23 15:16:00 +0000158@interface I1
159@end
Fariborz Jahaniana924f842013-09-25 19:36:32 +0000160
161// rdar://15051465
162@protocol SubFooling
163 @property(nonatomic, readonly) id hoho; // expected-note 2 {{property declared here}}
164@end
165
166@protocol Fooing<SubFooling>
167 @property(nonatomic, readonly) id muahahaha; // expected-note 2 {{property declared here}}
168@end
169
170typedef NSObject<Fooing> FooObject;
171
172@interface Okay : NSObject<Fooing>
173@end
174
175@implementation Okay // expected-warning 2 {{auto property synthesis will not synthesize property declared in a protocol}}
176@end
177
178@interface Fail : FooObject
179@end
180
181@implementation Fail // expected-warning 2 {{auto property synthesis will not synthesize property declared in a protocol}}
182@end
183