1 // RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -Wunguarded-availability -fblocks -fsyntax-only -verify %s
2 // RUN: %clang_cc1 -xobjective-c++ -std=c++11 -DOBJCPP -triple x86_64-apple-macosx10.9 -Wunguarded-availability -fblocks -fsyntax-only -verify %s
4 #define AVAILABLE_10_0 __attribute__((availability(macos, introduced = 10.0)))
5 #define AVAILABLE_10_11 __attribute__((availability(macos, introduced = 10.11)))
6 #define AVAILABLE_10_12 __attribute__((availability(macos, introduced = 10.12)))
8 typedef int AVAILABLE_10_12 new_int; // expected-note + {{'new_int' has been marked as being introduced in macOS 10.12 here, but the deployment target is macOS 10.9}}
10 int func_10_11(void) AVAILABLE_10_11; // expected-note 8 {{'func_10_11' has been marked as being introduced in macOS 10.11 here, but the deployment target is macOS 10.9}}
13 // expected-note@+2 6 {{'func_10_12' has been marked as being introduced in macOS 10.12 here, but the deployment target is macOS 10.9}}
15 int func_10_12(void) AVAILABLE_10_12; // expected-note 7 {{'func_10_12' has been marked as being introduced in macOS 10.12 here, but the deployment target is macOS 10.9}}
17 int func_10_0(void) AVAILABLE_10_0;
20 func_10_11(); // expected-warning{{'func_10_11' is only available on macOS 10.11 or newer}} expected-note{{enclose 'func_10_11' in an @available check to silence this warning}}
22 if (@available(macos 10.11, *))
25 func_10_11(); // expected-warning{{'func_10_11' is only available on macOS 10.11 or newer}} expected-note{{enclose 'func_10_11' in an @available check to silence this warning}}
28 void defn_10_11(void) AVAILABLE_10_11;
30 void defn_10_11(void) {
34 void nested_ifs(void) {
35 if (@available(macos 10.12, *)) {
36 if (@available(macos 10.10, *)) {
42 func_10_12(); // expected-warning{{'func_10_12' is only available on macOS 10.12 or newer}} expected-note{{enclose 'func_10_12' in an @available check to silence this warning}}
46 void star_case(void) {
47 if (@available(ios 9, *)) {
48 func_10_11(); // expected-warning{{'func_10_11' is only available on macOS 10.11 or newer}} expected-note{{enclose 'func_10_11' in an @available check to silence this warning}}
51 func_10_11(); // expected-warning{{'func_10_11' is only available on macOS 10.11 or newer}} expected-note{{enclose 'func_10_11' in an @available check to silence this warning}}
53 if (@available(macOS 10.11, *)) {
54 if (@available(ios 8, *)) {
56 func_10_12(); // expected-warning{{'func_10_12' is only available on macOS 10.12 or newer}} expected-note{{enclose}}
59 func_10_12(); // expected-warning{{'func_10_12' is only available on macOS 10.12 or newer}} expected-note{{enclose}}
64 typedef int int_10_11 AVAILABLE_10_11; // expected-note {{'int_10_11' has been marked as being introduced in macOS 10.11 here, but the deployment target is macOS 10.9}}
66 // expected-note@+2 {{'int_10_12' has been marked as being introduced in macOS 10.12 here, but the deployment target is macOS 10.9}}
68 typedef int int_10_12 AVAILABLE_10_12; // expected-note 2 {{'int_10_12' has been marked as being introduced in macOS 10.12 here, but the deployment target is macOS 10.9}}
70 void use_typedef(void) {
71 int_10_11 x; // expected-warning{{'int_10_11' is only available on macOS 10.11 or newer}} expected-note{{enclose 'int_10_11' in an @available check to silence this warning}}
74 __attribute__((objc_root_class))
75 AVAILABLE_10_11 @interface Class_10_11 { // expected-note{{annotate 'Class_10_11' with an availability attribute to silence}}
77 int_10_12 bar; // expected-warning {{'int_10_12' is only available on macOS 10.12 or newer}}
83 @implementation Class_10_11
86 func_10_12(); // expected-warning{{'func_10_12' is only available on macOS 10.12 or newer}} expected-note{{enclose 'func_10_12' in an @available check to silence this warning}}
89 - (void)method2 AVAILABLE_10_12 {
95 int protected_scope(void) {
96 if (@available(macos 10.20, *)) { // expected-note 2 {{jump enters controlled statement of if available}}
101 goto label1; // expected-error{{cannot jump from this goto statement to its label}}
104 goto label2; // expected-error{{cannot jump from this goto statement to its label}}
109 int m2 __attribute__((availability(macos, introduced = 10.12))); // expected-note{{has been marked as being introduced in macOS 10.12 here, but the deployment target is macOS 10.9}}
112 int nested_member __attribute__((availability(macos, introduced = 10.12))); // expected-note{{'nested_member' has been marked as being introduced in macOS 10.12 here, but the deployment target is macOS 10.9}}
116 int test_members(void) {
119 (void)s.m2; // expected-warning{{'m2' is only available on macOS 10.12 or newer}} expected-note{{@available}}
121 (void)s.n.nested_member; // expected-warning{{'nested_member' is only available on macOS 10.12 or newer}} expected-note{{@available}}
124 void test_blocks(void) {
126 func_10_12(); // expected-warning{{'func_10_12' is only available on macOS 10.12 or newer}} expected-note{{@available}}
129 if (@available(macos 10.12, *))
138 void test_params(int_10_12 x); // expected-warning {{'int_10_12' is only available on macOS 10.12 or newer}} expected-note{{annotate 'test_params' with an availability attribute to silence this warning}}
140 void test_params2(int_10_12 x) AVAILABLE_10_12; // no warn
142 void (^topLevelBlockDecl)(void) = ^ {
143 func_10_12(); // expected-warning{{'func_10_12' is only available on macOS 10.12 or newer}} expected-note{{@available}}
144 if (@available(macos 10.12, *))
149 __attribute__((objc_root_class))
150 @interface InterWithProp // expected-note 2 {{'InterWithProp' has been marked as being introduced in macOS 10.12 here, but the deployment target is macOS 10.9}}
151 @property(class) int x;
152 + (void) setX: (int)newX AVAILABLE_10_12; // expected-note{{'setX:' has been marked as being introduced in macOS 10.12 here, but the deployment target is macOS 10.9}}
154 void test_property(void) {
155 int y = InterWithProp.x; // expected-warning{{'InterWithProp' is only available on macOS 10.12 or newer}} expected-note{{@available}}
156 InterWithProp.x = y; // expected-warning{{'InterWithProp' is only available on macOS 10.12 or newer}} expected-note{{@available}} expected-warning{{'setX:' is only available on macOS 10.12 or newer}} expected-note{{@available}}
159 __attribute__((objc_root_class))
160 @interface Subscriptable
161 - (id)objectAtIndexedSubscript:(int)sub AVAILABLE_10_12; // expected-note{{'objectAtIndexedSubscript:' has been marked as being introduced in macOS 10.12 here, but the deployment target is macOS 10.9}}
164 void test_at(Subscriptable *x) {
165 id y = x[42]; // expected-warning{{'objectAtIndexedSubscript:' is only available on macOS 10.12 or newer}} expected-note{{@available}}
168 void uncheckAtAvailable(void) {
169 if (@available(macOS 10.12, *) || 0) // expected-warning {{@available does not guard availability here; use if (@available) instead}}
170 func_10_12(); // expected-warning {{'func_10_12' is only available on macOS 10.12 or newer}}
171 // expected-note@-1 {{enclose 'func_10_12' in an @available check to silence this warning}}
174 void justAtAvailable(void) {
175 int availability = @available(macOS 10.12, *); // expected-warning {{@available does not guard availability here; use if (@available) instead}}
180 int f(char) AVAILABLE_10_12;
183 template <class T> int use_f() {
184 // FIXME: We should warn here!
188 int a = use_f<int>();
189 int b = use_f<char>();
191 template <class> int use_at_available() {
192 if (@available(macos 10.12, *))
195 return func_10_12(); // expected-warning {{'func_10_12' is only available on macOS 10.12 or newer}} expected-note{{enclose}}
198 int instantiate_template() {
199 if (@available(macos 10.12, *)) {
200 use_at_available<char>();
202 use_at_available<float>();
207 int with_availability_attr() AVAILABLE_10_11 { // expected-note 2 {{'with_availability_attr<int>' has been marked as being introduced in macOS 10.11 here, but the deployment target is macOS 10.9}}
211 int instantiate_with_availability_attr() {
212 if (@available(macos 10.12, *))
213 with_availability_attr<char>();
215 with_availability_attr<int>(); // expected-warning {{'with_availability_attr<int>' is only available on macOS 10.11 or newer}} expected-note {{enclose}}
218 int instantiate_availability() {
219 if (@available(macOS 10.12, *))
220 with_availability_attr<int_10_12>();
222 with_availability_attr<int_10_12>(); // expected-warning{{'with_availability_attr<int>' is only available on macOS 10.11 or newer}} expected-warning{{'int_10_12' is only available on macOS 10.12 or newer}} expected-note 2 {{enclose}}
225 auto topLevelLambda = [] () {
226 func_10_12(); // expected-warning{{'func_10_12' is only available on macOS 10.12 or newer}} expected-note{{@available}}
227 if (@available(macos 10.12, *))
231 void functionInFunction() {
232 func_10_12(); // expected-warning{{'func_10_12' is only available on macOS 10.12 or newer}} expected-note{{@available}}
233 struct DontWarnTwice {
235 func_10_12(); // expected-warning{{'func_10_12' is only available on macOS 10.12 or newer}} expected-note{{@available}}
239 func_10_12(); // expected-warning{{'func_10_12' is only available on macOS 10.12 or newer}} expected-note{{@available}}
242 func_10_12(); // expected-warning{{'func_10_12' is only available on macOS 10.12 or newer}} expected-note{{@available}}
245 if (@available(macos 10.12, *)) {
259 if (@available(macos 10.12, *)) {
278 struct InStruct { // expected-note{{annotate 'InStruct' with an availability attribute to silence}}
279 new_int mem; // expected-warning{{'new_int' is only available on macOS 10.12 or newer}}
281 struct { new_int mem; } anon; // expected-warning{{'new_int' is only available on macOS 10.12 or newer}} expected-note{{annotate anonymous struct with an availability attribute to silence}}
285 static constexpr int AVAILABLE_10_12 SomeConstexprValue = 2; // expected-note{{'SomeConstexprValue' has been marked as being introduced in macOS 10.12 here, but the deployment target is macOS 10.9}}
286 typedef enum { // expected-note{{annotate anonymous enum with an availability attribute}}
287 SomeValue = SomeConstexprValue // expected-warning{{'SomeConstexprValue' is only available on macOS 10.12 or newer}}
291 @interface InInterface
292 -(new_int)meth; // expected-warning{{'new_int' is only available on macOS 10.12 or newer}} expected-note{{annotate 'meth' with an availability attribute}}
295 @interface Proper // expected-note{{annotate 'Proper' with an availability attribute}}
296 @property (class) new_int x; // expected-warning{{'new_int' is only available}}
299 void with_local_struct(void) {
301 new_int x; // expected-warning{{'new_int' is only available}} expected-note{{enclose 'new_int' in an @available check}}
303 if (@available(macos 10.12, *)) {
310 // Avoid the warning on protocol requirements.
313 @protocol NewProtocol // expected-note {{'NewProtocol' has been marked as being introduced in macOS 10.12 here, but the deployment target is macOS 10.9}}
316 @protocol ProtocolWithNewProtocolRequirement <NewProtocol> // expected-note {{annotate 'ProtocolWithNewProtocolRequirement' with an availability attribute to silence}}
318 @property(copy) id<NewProtocol> prop; // expected-warning {{'NewProtocol' is only available on macOS 10.12 or newer}}
325 @interface ClassWithNewProtocolRequirement : BaseClass <NewProtocol>
329 @interface BaseClass (CategoryWithNewProtocolRequirement) <NewProtocol>
334 AK_Dodo __attribute__((availability(macos, deprecated=10.3))), // expected-note 3 {{marked deprecated here}}
335 AK_Cat __attribute__((availability(macos, introduced=10.4))),
336 AK_CyborgCat __attribute__((availability(macos, introduced=10.12))), // expected-note {{'AK_CyborgCat' has been marked as being introduced in macOS 10.12 here, but the deployment target is macOS 10.9}}
339 void switchAnimals(Animals a) {
341 case AK_Dodo: break; // expected-warning{{'AK_Dodo' is deprecated}}
343 case AK_Cat|AK_CyborgCat: break; // expected-warning{{case value not in enum}}
344 case AK_CyborgCat: break; // no warn
348 case AK_Dodo...AK_CyborgCat: // expected-warning {{'AK_Dodo' is depr}}
352 (void)AK_Dodo; // expected-warning{{'AK_Dodo' is deprecated}}
353 (void)AK_Cat; // no warning
354 (void)AK_CyborgCat; // expected-warning{{'AK_CyborgCat' is only available on macOS 10.12 or newer}} expected-note {{@available}}
358 // test static initializers has the same availability as the deployment target and it cannot be overwritten.
359 @interface HasStaticInitializer : BaseClass
360 + (void)load AVAILABLE_10_11; // expected-warning{{ignoring availability attribute on '+load' method}}
363 @implementation HasStaticInitializer
365 func_10_11(); // expected-warning{{'func_10_11' is only available on macOS 10.11 or newer}} expected-note{{enclose 'func_10_11' in an @available check to silence this warning}}
369 // test availability from interface is ignored when checking the unguarded availability in +load method.
371 @interface HasStaticInitializer1 : BaseClass
373 + (void)load: (int)x; // no warning.
376 @implementation HasStaticInitializer1
378 func_10_11(); // expected-warning{{'func_10_11' is only available on macOS 10.11 or newer}} expected-note{{enclose 'func_10_11' in an @available check to silence this warning}}
380 + (void)load: (int)x {
381 func_10_11(); // no warning.
385 __attribute__((constructor))
386 void is_constructor(void);
388 AVAILABLE_10_11 // expected-warning{{ignoring availability attribute with constructor attribute}}
389 void is_constructor(void) {
390 func_10_11(); // expected-warning{{'func_10_11' is only available on macOS 10.11 or newer}} expected-note{{enclose 'func_10_11' in an @available check to silence this warning}}
393 AVAILABLE_10_11 // expected-warning{{ignoring availability attribute with destructor attribute}}
394 __attribute__((destructor))
395 void is_destructor(void) {
396 func_10_11(); // expected-warning{{'func_10_11' is only available on macOS 10.11 or newer}} expected-note{{enclose 'func_10_11' in an @available check to silence this warning}}