1 // RUN: %clang_cc1 -triple x86_64-apple-darwin9.0.0 -fsyntax-only -verify %s
2 // RUN: %clang_cc1 -D WARN_PARTIAL -Wpartial-availability -triple x86_64-apple-darwin9.0.0 -fsyntax-only -verify %s
5 - (void)proto_method __attribute__((availability(macosx,introduced=10.1,deprecated=10.2))); // expected-note 2 {{'proto_method' has been explicitly marked deprecated here}}
7 #if defined(WARN_PARTIAL)
8 // expected-note@+2 2 {{'partial_proto_method' has been marked as being introduced in macOS 10.8 here, but the deployment target is macOS 10.5}}
10 - (void)partial_proto_method __attribute__((availability(macosx,introduced=10.8)));
14 - (void)method __attribute__((availability(macosx,introduced=10.1,deprecated=10.2))); // expected-note {{'method' has been explicitly marked deprecated here}}
15 #if defined(WARN_PARTIAL)
16 // expected-note@+2 2 {{'partialMethod' has been marked as being introduced in macOS 10.8 here, but the deployment target is macOS 10.5}}
18 - (void)partialMethod __attribute__((availability(macosx,introduced=10.8)));
20 - (void)overridden __attribute__((availability(macosx,introduced=10.3))); // expected-note{{overridden method is here}}
21 - (void)overridden2 __attribute__((availability(macosx,introduced=10.3)));
22 - (void)overridden3 __attribute__((availability(macosx,deprecated=10.3)));
23 - (void)overridden4 __attribute__((availability(macosx,deprecated=10.3))); // expected-note{{overridden method is here}}
24 - (void)overridden5 __attribute__((availability(macosx,unavailable)));
25 - (void)overridden6 __attribute__((availability(macosx,introduced=10.3))); // expected-note{{overridden method is here}}
26 - (void)unavailableMethod __attribute__((unavailable));
31 - (void)method; // NOTE: we expect 'method' to *not* inherit availability.
32 - (void)partialMethod; // Likewise.
33 - (void)overridden __attribute__((availability(macosx,introduced=10.4))); // expected-warning{{overriding method introduced after overridden method on macOS (10.4 vs. 10.3)}}
34 - (void)overridden2 __attribute__((availability(macosx,introduced=10.2)));
35 - (void)overridden3 __attribute__((availability(macosx,deprecated=10.4)));
36 - (void)overridden4 __attribute__((availability(macosx,deprecated=10.2))); // expected-warning{{overriding method deprecated before overridden method on macOS (10.3 vs. 10.2)}}
37 - (void)overridden5 __attribute__((availability(macosx,introduced=10.3)));
38 - (void)overridden6 __attribute__((availability(macosx,unavailable))); // expected-warning{{overriding method cannot be unavailable on macOS when its overridden method is available}}
39 - (void)unavailableMethod; // does *not* inherit unavailability
43 [a method]; // expected-warning{{'method' is deprecated: first deprecated in macOS 10.2}}
44 [b method]; // no-warning
45 [a proto_method]; // expected-warning{{'proto_method' is deprecated: first deprecated in macOS 10.2}}
46 [b proto_method]; // expected-warning{{'proto_method' is deprecated: first deprecated in macOS 10.2}}
48 #if defined(WARN_PARTIAL)
49 // expected-warning@+2 {{'partialMethod' is only available on macOS 10.8 or newer}} expected-note@+2 {{enclose 'partialMethod' in an @available check to silence this warning}}
52 [b partialMethod]; // no warning
53 #if defined(WARN_PARTIAL)
54 // expected-warning@+2 {{'partial_proto_method' is only available on macOS 10.8 or newer}} expected-note@+2 {{enclose 'partial_proto_method' in an @available check to silence this warning}}
56 [a partial_proto_method];
57 #if defined(WARN_PARTIAL)
58 // expected-warning@+2 {{'partial_proto_method' is only available on macOS 10.8 or newer}} expected-note@+2 {{enclose 'partial_proto_method' in an @available check to silence this warning}}
60 [b partial_proto_method];
64 - (void)partialMethod;
65 - (void)partial_proto_method;
68 void f_after_redecl(A *a, B *b) {
70 // expected-warning@+2{{'partialMethod' is only available on macOS 10.8 or newer}} expected-note@+2 {{@available}}
73 [b partialMethod]; // no warning
74 [a partial_proto_method]; // no warning
75 [b partial_proto_method]; // no warning
78 // Test case for <rdar://problem/11627873>. Warn about
79 // using a deprecated method when that method is re-implemented in a
80 // subclass where the redeclared method is not deprecated.
82 - (void) method __attribute__((availability(macosx,introduced=10.1,deprecated=10.2))); // expected-note {{'method' has been explicitly marked deprecated here}}
95 [super method]; // expected-warning {{'method' is deprecated: first deprecated in macOS 10.2}}
101 [super method]; // no-warning
106 @class NSMutableArray;
108 @interface NSDictionary
109 + (instancetype)dictionaryWithObjectsAndKeys:(id)firstObject, ... __attribute__((sentinel(0,1)));
114 extern NSString *NSNibTopLevelObjects __attribute__((availability(macosx,introduced=10.0 ,deprecated=10.8,message="" )));
115 id NSNibOwner, topNibObjects;
117 @interface AppDelegate (SIEImport) // expected-error {{cannot find interface declaration for 'AppDelegate'}}
119 -(void)__attribute__((ibaction))importFromSIE:(id)sender;
123 @implementation AppDelegate (SIEImport) // expected-error {{cannot find interface declaration for 'AppDelegate'}}
125 -(void)__attribute__((ibaction))importFromSIE:(id)sender {
127 NSMutableArray *topNibObjects;
128 NSDictionary *nibLoadDict = [NSDictionary dictionaryWithObjectsAndKeys:self, NSNibOwner, topNibObjects, NSNibTopLevelObjects, ((void *)0)];
133 @protocol PartialProt
134 - (void)ppartialMethod __attribute__((availability(macosx,introduced=10.8)));
135 + (void)ppartialMethod __attribute__((availability(macosx,introduced=10.8)));
138 @interface PartialI <PartialProt>
140 // expected-note@+3{{'partialMethod' has been marked as being introduced in macOS 10.8 here, but the deployment target is macOS 10.5}}
141 // expected-note@+3{{'partialMethod' has been marked as being introduced in macOS 10.8 here, but the deployment target is macOS 10.5}}
143 - (void)partialMethod __attribute__((availability(macosx,introduced=10.8)));
144 + (void)partialMethod __attribute__((availability(macosx,introduced=10.8)));
147 @interface PartialI ()
148 - (void)ipartialMethod1 __attribute__((availability(macosx,introduced=10.8)));
149 #if defined(WARN_PARTIAL)
150 // expected-note@+2 {{'ipartialMethod2' has been marked as being introduced in macOS 10.8 here, but the deployment target is macOS 10.5}}
152 - (void)ipartialMethod2 __attribute__((availability(macosx,introduced=10.8)));
153 + (void)ipartialMethod1 __attribute__((availability(macosx,introduced=10.8)));
154 #if defined(WARN_PARTIAL)
155 // expected-note@+2 {{'ipartialMethod2' has been marked as being introduced in macOS 10.8 here, but the deployment target is macOS 10.5}}
157 + (void)ipartialMethod2 __attribute__((availability(macosx,introduced=10.8)));
160 @interface PartialI (Redecls)
161 - (void)partialMethod;
162 - (void)ipartialMethod1;
163 - (void)ppartialMethod;
164 + (void)partialMethod;
165 + (void)ipartialMethod1;
166 + (void)ppartialMethod;
169 void partialfun(PartialI* a) {
171 // expected-warning@+2 {{'partialMethod' is only available on macOS 10.8 or newer}} expected-note@+2{{@available}}
174 [a ipartialMethod1]; // no warning
175 #if defined(WARN_PARTIAL)
176 // expected-warning@+2 {{'ipartialMethod2' is only available on macOS 10.8 or newer}} expected-note@+2 {{enclose 'ipartialMethod2' in an @available check to silence this warning}}
179 [a ppartialMethod]; // no warning
181 // expected-warning@+2 {{'partialMethod' is only available on macOS 10.8 or newer}} expected-note@+2 {{@available}}
183 [PartialI partialMethod];
184 [PartialI ipartialMethod1]; // no warning
185 #if defined(WARN_PARTIAL)
186 // expected-warning@+2 {{'ipartialMethod2' is only available on macOS 10.8 or newer}} expected-note@+2 {{enclose 'ipartialMethod2' in an @available check to silence this warning}}
188 [PartialI ipartialMethod2];
189 [PartialI ppartialMethod]; // no warning
192 #if defined(WARN_PARTIAL)
193 // expected-note@+2 2 {{'PartialI2' has been marked as being introduced in macOS 10.8 here, but the deployment target is macOS 10.5}}
195 __attribute__((availability(macosx, introduced = 10.8))) @interface PartialI2
198 #if defined(WARN_PARTIAL)
199 // expected-warning@+2 {{'PartialI2' is only available on macOS 10.8 or newer}} expected-note@+2 {{annotate 'partialinter1' with an availability attribute to silence}}
201 void partialinter1(PartialI2* p) {
207 // expected-warning@+2 {{'PartialI2' is only available on macOS 10.8 or newer}} expected-note@+2 {{annotate 'partialinter2' with an availability attribute to silence}}
209 void partialinter2(PartialI2* p) {
213 // Test that both the use of the 'typedef' and the enum constant
214 // produces an error. rdar://problem/20903588
215 #define UNAVAILABLE __attribute__((unavailable("not available")))
217 typedef enum MyEnum : int MyEnum;
218 enum MyEnum : int { // expected-note {{'MyEnum' has been explicitly marked unavailable here}}
219 MyEnum_Blah UNAVAILABLE, // expected-note {{'MyEnum_Blah' has been explicitly marked unavailable here}}
222 void use_myEnum(void) {
223 // expected-error@+2 {{'MyEnum' is unavailable: not available}}
224 // expected-error@+1 {{MyEnum_Blah' is unavailable: not available}}
225 MyEnum e = MyEnum_Blah;
228 // Test that the availability of (optional) protocol methods is not
229 // inherited be implementations of those protocol methods.
230 @protocol AvailabilityP2
232 -(void)methodA __attribute__((availability(macosx,introduced=10.1,deprecated=10.2))); // expected-note 4{{'methodA' has been explicitly marked deprecated here}}
233 -(void)methodB __attribute__((unavailable)); // expected-note 4{{'methodB' has been explicitly marked unavailable here}}
237 void testAvailabilityP2(id<AvailabilityP2> obj) {
238 [obj methodA]; // expected-warning{{'methodA' is deprecated: first deprecated in macOS 10.2}}
239 [obj methodB]; // expected-error{{'methodB' is unavailable}}
242 @interface ImplementsAvailabilityP2a <AvailabilityP2>
247 void testImplementsAvailabilityP2a(ImplementsAvailabilityP2a *obj) {
248 [obj methodA]; // okay: availability not inherited
249 [obj methodB]; // okay: unavailability not inherited
252 __attribute__((objc_root_class))
253 @interface ImplementsAvailabilityP2b <AvailabilityP2>
256 @implementation ImplementsAvailabilityP2b
258 // Make sure we're not inheriting availability.
259 id<AvailabilityP2> obj = self;
260 [obj methodA]; // expected-warning{{'methodA' is deprecated: first deprecated in macOS 10.2}}
261 [obj methodB]; // expected-error{{'methodB' is unavailable}}
264 // Make sure we're not inheriting unavailability.
265 id<AvailabilityP2> obj = self;
266 [obj methodA]; // expected-warning{{'methodA' is deprecated: first deprecated in macOS 10.2}}
267 [obj methodB]; // expected-error{{'methodB' is unavailable}}
272 void testImplementsAvailabilityP2b(ImplementsAvailabilityP2b *obj) {
273 // still get warnings/errors because we see the protocol version.
275 [obj methodA]; // expected-warning{{'methodA' is deprecated: first deprecated in macOS 10.2}}
276 [obj methodB]; // expected-error{{'methodB' is unavailable}}
279 __attribute__((objc_root_class))
280 @interface ImplementsAvailabilityP2c <AvailabilityP2>
281 -(void)methodA __attribute__((availability(macosx,introduced=10.2)));
282 -(void)methodB __attribute__((unavailable));
285 __attribute__((objc_root_class))
286 @interface ImplementsAvailabilityP2d <AvailabilityP2>
289 @implementation ImplementsAvailabilityP2d
290 -(void)methodA __attribute__((availability(macosx,introduced=10.2)))
293 -(void)methodB __attribute__((unavailable)) {
297 __attribute__((objc_root_class))
298 @interface InheritUnavailableSuper
299 -(void)method __attribute__((unavailable)); // expected-note{{'method' has been explicitly marked unavailable here}}
302 @interface InheritUnavailableSub : InheritUnavailableSuper
306 @implementation InheritUnavailableSub
308 InheritUnavailableSuper *obj = self;
309 [obj method]; // expected-error{{'method' is unavailable}}
313 #if defined(WARN_PARTIAL)
315 int fn_10_5(void) __attribute__((availability(macosx, introduced=10.5)));
316 int fn_10_7(void) __attribute__((availability(macosx, introduced=10.7))); // expected-note{{'fn_10_7' has been marked as being introduced in macOS 10.7 here, but the deployment target is macOS 10.5}}
317 int fn_10_8(void) __attribute__((availability(macosx, introduced=10.8))) { // expected-note{{'fn_10_8' has been marked as being introduced in macOS 10.8 here, but the deployment target is macOS 10.5}}
321 __attribute__((objc_root_class))
322 @interface LookupAvailabilityBase
326 @implementation LookupAvailabilityBase
327 -(void)method1 { fn_10_7(); } // expected-warning{{only available on macOS 10.7}} expected-note{{@available}}
330 __attribute__((availability(macosx, introduced=10.7)))
331 @interface LookupAvailability : LookupAvailabilityBase
334 - (void)method4 __attribute__((availability(macosx, introduced=10.8)));
337 @implementation LookupAvailability
338 -(void)method2 { fn_10_7(); }
339 -(void)method3 { fn_10_8(); } // expected-warning{{only available on macOS 10.8}} expected-note{{@available}}
340 -(void)method4 { fn_10_8(); }
343 int old_func(void) __attribute__((availability(macos, introduced=10.4))) {