annotate clang/test/SemaObjC/unguarded-availability.m @ 207:2e18cbf3894f

LLVM12
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Tue, 08 Jun 2021 06:07:14 +0900
parents 1d019706d866
children c4bab56944e8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 // RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -Wunguarded-availability -fblocks -fsyntax-only -verify %s
anatofuz
parents:
diff changeset
2 // RUN: %clang_cc1 -xobjective-c++ -std=c++11 -DOBJCPP -triple x86_64-apple-macosx10.9 -Wunguarded-availability -fblocks -fsyntax-only -verify %s
anatofuz
parents:
diff changeset
3
anatofuz
parents:
diff changeset
4 #define AVAILABLE_10_0 __attribute__((availability(macos, introduced = 10.0)))
anatofuz
parents:
diff changeset
5 #define AVAILABLE_10_11 __attribute__((availability(macos, introduced = 10.11)))
anatofuz
parents:
diff changeset
6 #define AVAILABLE_10_12 __attribute__((availability(macos, introduced = 10.12)))
anatofuz
parents:
diff changeset
7
anatofuz
parents:
diff changeset
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.0}}
anatofuz
parents:
diff changeset
9
anatofuz
parents:
diff changeset
10 int func_10_11() 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.0}}
anatofuz
parents:
diff changeset
11
anatofuz
parents:
diff changeset
12 #ifdef OBJCPP
anatofuz
parents:
diff changeset
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.0}}
anatofuz
parents:
diff changeset
14 #endif
anatofuz
parents:
diff changeset
15 int func_10_12() 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.0}}
anatofuz
parents:
diff changeset
16
anatofuz
parents:
diff changeset
17 int func_10_0() AVAILABLE_10_0;
anatofuz
parents:
diff changeset
18
anatofuz
parents:
diff changeset
19 void use_func() {
anatofuz
parents:
diff changeset
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}}
anatofuz
parents:
diff changeset
21
anatofuz
parents:
diff changeset
22 if (@available(macos 10.11, *))
anatofuz
parents:
diff changeset
23 func_10_11();
anatofuz
parents:
diff changeset
24 else
anatofuz
parents:
diff changeset
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}}
anatofuz
parents:
diff changeset
26 }
anatofuz
parents:
diff changeset
27
anatofuz
parents:
diff changeset
28 void defn_10_11() AVAILABLE_10_11;
anatofuz
parents:
diff changeset
29
anatofuz
parents:
diff changeset
30 void defn_10_11() {
anatofuz
parents:
diff changeset
31 func_10_11();
anatofuz
parents:
diff changeset
32 }
anatofuz
parents:
diff changeset
33
anatofuz
parents:
diff changeset
34 void nested_ifs() {
anatofuz
parents:
diff changeset
35 if (@available(macos 10.12, *)) {
anatofuz
parents:
diff changeset
36 if (@available(macos 10.10, *)) {
anatofuz
parents:
diff changeset
37 func_10_12();
anatofuz
parents:
diff changeset
38 } else {
anatofuz
parents:
diff changeset
39 func_10_12();
anatofuz
parents:
diff changeset
40 }
anatofuz
parents:
diff changeset
41 } else {
anatofuz
parents:
diff changeset
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}}
anatofuz
parents:
diff changeset
43 }
anatofuz
parents:
diff changeset
44 }
anatofuz
parents:
diff changeset
45
anatofuz
parents:
diff changeset
46 void star_case() {
anatofuz
parents:
diff changeset
47 if (@available(ios 9, *)) {
anatofuz
parents:
diff changeset
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}}
anatofuz
parents:
diff changeset
49 func_10_0();
anatofuz
parents:
diff changeset
50 } else
anatofuz
parents:
diff changeset
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}}
anatofuz
parents:
diff changeset
52
anatofuz
parents:
diff changeset
53 if (@available(macOS 10.11, *)) {
anatofuz
parents:
diff changeset
54 if (@available(ios 8, *)) {
anatofuz
parents:
diff changeset
55 func_10_11();
anatofuz
parents:
diff changeset
56 func_10_12(); // expected-warning{{'func_10_12' is only available on macOS 10.12 or newer}} expected-note{{enclose}}
anatofuz
parents:
diff changeset
57 } else {
anatofuz
parents:
diff changeset
58 func_10_11();
anatofuz
parents:
diff changeset
59 func_10_12(); // expected-warning{{'func_10_12' is only available on macOS 10.12 or newer}} expected-note{{enclose}}
anatofuz
parents:
diff changeset
60 }
anatofuz
parents:
diff changeset
61 }
anatofuz
parents:
diff changeset
62 }
anatofuz
parents:
diff changeset
63
anatofuz
parents:
diff changeset
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.0}}
anatofuz
parents:
diff changeset
65 #ifdef OBJCPP
anatofuz
parents:
diff changeset
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.0}}
anatofuz
parents:
diff changeset
67 #endif
anatofuz
parents:
diff changeset
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.0}}
anatofuz
parents:
diff changeset
69
anatofuz
parents:
diff changeset
70 void use_typedef() {
anatofuz
parents:
diff changeset
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}}
anatofuz
parents:
diff changeset
72 }
anatofuz
parents:
diff changeset
73
anatofuz
parents:
diff changeset
74 __attribute__((objc_root_class))
anatofuz
parents:
diff changeset
75 AVAILABLE_10_11 @interface Class_10_11 { // expected-note{{annotate 'Class_10_11' with an availability attribute to silence}}
anatofuz
parents:
diff changeset
76 int_10_11 foo;
anatofuz
parents:
diff changeset
77 int_10_12 bar; // expected-warning {{'int_10_12' is only available on macOS 10.12 or newer}}
anatofuz
parents:
diff changeset
78 }
anatofuz
parents:
diff changeset
79 - (void)method1;
anatofuz
parents:
diff changeset
80 - (void)method2;
anatofuz
parents:
diff changeset
81 @end
anatofuz
parents:
diff changeset
82
anatofuz
parents:
diff changeset
83 @implementation Class_10_11
anatofuz
parents:
diff changeset
84 - (void) method1 {
anatofuz
parents:
diff changeset
85 func_10_11();
anatofuz
parents:
diff changeset
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}}
anatofuz
parents:
diff changeset
87 }
anatofuz
parents:
diff changeset
88
anatofuz
parents:
diff changeset
89 - (void)method2 AVAILABLE_10_12 {
anatofuz
parents:
diff changeset
90 func_10_12();
anatofuz
parents:
diff changeset
91 }
anatofuz
parents:
diff changeset
92
anatofuz
parents:
diff changeset
93 @end
anatofuz
parents:
diff changeset
94
anatofuz
parents:
diff changeset
95 int protected_scope() {
anatofuz
parents:
diff changeset
96 if (@available(macos 10.20, *)) { // expected-note 2 {{jump enters controlled statement of if available}}
anatofuz
parents:
diff changeset
97 label1:
anatofuz
parents:
diff changeset
98 return 0;
anatofuz
parents:
diff changeset
99 } else {
anatofuz
parents:
diff changeset
100 label2:
anatofuz
parents:
diff changeset
101 goto label1; // expected-error{{cannot jump from this goto statement to its label}}
anatofuz
parents:
diff changeset
102 }
anatofuz
parents:
diff changeset
103
anatofuz
parents:
diff changeset
104 goto label2; // expected-error{{cannot jump from this goto statement to its label}}
anatofuz
parents:
diff changeset
105 }
anatofuz
parents:
diff changeset
106
anatofuz
parents:
diff changeset
107 struct S {
anatofuz
parents:
diff changeset
108 int m1;
anatofuz
parents:
diff changeset
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.0}}
anatofuz
parents:
diff changeset
110
anatofuz
parents:
diff changeset
111 struct Nested {
anatofuz
parents:
diff changeset
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.0}}
anatofuz
parents:
diff changeset
113 } n;
anatofuz
parents:
diff changeset
114 };
anatofuz
parents:
diff changeset
115
anatofuz
parents:
diff changeset
116 int test_members() {
anatofuz
parents:
diff changeset
117 struct S s;
anatofuz
parents:
diff changeset
118 (void)s.m1;
anatofuz
parents:
diff changeset
119 (void)s.m2; // expected-warning{{'m2' is only available on macOS 10.12 or newer}} expected-note{{@available}}
anatofuz
parents:
diff changeset
120
anatofuz
parents:
diff changeset
121 (void)s.n.nested_member; // expected-warning{{'nested_member' is only available on macOS 10.12 or newer}} expected-note{{@available}}
anatofuz
parents:
diff changeset
122 }
anatofuz
parents:
diff changeset
123
anatofuz
parents:
diff changeset
124 void test_blocks() {
anatofuz
parents:
diff changeset
125 (void) ^{
anatofuz
parents:
diff changeset
126 func_10_12(); // expected-warning{{'func_10_12' is only available on macOS 10.12 or newer}} expected-note{{@available}}
anatofuz
parents:
diff changeset
127 };
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
128
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
129 if (@available(macos 10.12, *))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
130 (void) ^{
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
131 func_10_12();
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
132 (void) ^{
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
133 func_10_12();
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
134 };
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
135 };
150
anatofuz
parents:
diff changeset
136 }
anatofuz
parents:
diff changeset
137
anatofuz
parents:
diff changeset
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}}
anatofuz
parents:
diff changeset
139
anatofuz
parents:
diff changeset
140 void test_params2(int_10_12 x) AVAILABLE_10_12; // no warn
anatofuz
parents:
diff changeset
141
anatofuz
parents:
diff changeset
142 void (^topLevelBlockDecl)() = ^ {
anatofuz
parents:
diff changeset
143 func_10_12(); // expected-warning{{'func_10_12' is only available on macOS 10.12 or newer}} expected-note{{@available}}
anatofuz
parents:
diff changeset
144 if (@available(macos 10.12, *))
anatofuz
parents:
diff changeset
145 func_10_12();
anatofuz
parents:
diff changeset
146 };
anatofuz
parents:
diff changeset
147
anatofuz
parents:
diff changeset
148 AVAILABLE_10_12
anatofuz
parents:
diff changeset
149 __attribute__((objc_root_class))
anatofuz
parents:
diff changeset
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.0}}
anatofuz
parents:
diff changeset
151 @property(class) int x;
anatofuz
parents:
diff changeset
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.0}}
anatofuz
parents:
diff changeset
153 @end
anatofuz
parents:
diff changeset
154 void test_property(void) {
anatofuz
parents:
diff changeset
155 int y = InterWithProp.x; // expected-warning{{'InterWithProp' is only available on macOS 10.12 or newer}} expected-note{{@available}}
anatofuz
parents:
diff changeset
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}}
anatofuz
parents:
diff changeset
157 }
anatofuz
parents:
diff changeset
158
anatofuz
parents:
diff changeset
159 __attribute__((objc_root_class))
anatofuz
parents:
diff changeset
160 @interface Subscriptable
anatofuz
parents:
diff changeset
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.0}}
anatofuz
parents:
diff changeset
162 @end
anatofuz
parents:
diff changeset
163
anatofuz
parents:
diff changeset
164 void test_at(Subscriptable *x) {
anatofuz
parents:
diff changeset
165 id y = x[42]; // expected-warning{{'objectAtIndexedSubscript:' is only available on macOS 10.12 or newer}} expected-note{{@available}}
anatofuz
parents:
diff changeset
166 }
anatofuz
parents:
diff changeset
167
anatofuz
parents:
diff changeset
168 void uncheckAtAvailable() {
anatofuz
parents:
diff changeset
169 if (@available(macOS 10.12, *) || 0) // expected-warning {{@available does not guard availability here; use if (@available) instead}}
anatofuz
parents:
diff changeset
170 func_10_12(); // expected-warning {{'func_10_12' is only available on macOS 10.12 or newer}}
anatofuz
parents:
diff changeset
171 // expected-note@-1 {{enclose 'func_10_12' in an @available check to silence this warning}}
anatofuz
parents:
diff changeset
172 }
anatofuz
parents:
diff changeset
173
anatofuz
parents:
diff changeset
174 void justAtAvailable() {
anatofuz
parents:
diff changeset
175 int availability = @available(macOS 10.12, *); // expected-warning {{@available does not guard availability here; use if (@available) instead}}
anatofuz
parents:
diff changeset
176 }
anatofuz
parents:
diff changeset
177
anatofuz
parents:
diff changeset
178 #ifdef OBJCPP
anatofuz
parents:
diff changeset
179
anatofuz
parents:
diff changeset
180 int f(char) AVAILABLE_10_12;
anatofuz
parents:
diff changeset
181 int f(int);
anatofuz
parents:
diff changeset
182
anatofuz
parents:
diff changeset
183 template <class T> int use_f() {
anatofuz
parents:
diff changeset
184 // FIXME: We should warn here!
anatofuz
parents:
diff changeset
185 return f(T());
anatofuz
parents:
diff changeset
186 }
anatofuz
parents:
diff changeset
187
anatofuz
parents:
diff changeset
188 int a = use_f<int>();
anatofuz
parents:
diff changeset
189 int b = use_f<char>();
anatofuz
parents:
diff changeset
190
anatofuz
parents:
diff changeset
191 template <class> int use_at_available() {
anatofuz
parents:
diff changeset
192 if (@available(macos 10.12, *))
anatofuz
parents:
diff changeset
193 return func_10_12();
anatofuz
parents:
diff changeset
194 else
anatofuz
parents:
diff changeset
195 return func_10_12(); // expected-warning {{'func_10_12' is only available on macOS 10.12 or newer}} expected-note{{enclose}}
anatofuz
parents:
diff changeset
196 }
anatofuz
parents:
diff changeset
197
anatofuz
parents:
diff changeset
198 int instantiate_template() {
anatofuz
parents:
diff changeset
199 if (@available(macos 10.12, *)) {
anatofuz
parents:
diff changeset
200 use_at_available<char>();
anatofuz
parents:
diff changeset
201 } else {
anatofuz
parents:
diff changeset
202 use_at_available<float>();
anatofuz
parents:
diff changeset
203 }
anatofuz
parents:
diff changeset
204 }
anatofuz
parents:
diff changeset
205
anatofuz
parents:
diff changeset
206 template <class>
anatofuz
parents:
diff changeset
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.0}}
anatofuz
parents:
diff changeset
208 return 0;
anatofuz
parents:
diff changeset
209 }
anatofuz
parents:
diff changeset
210
anatofuz
parents:
diff changeset
211 int instantiate_with_availability_attr() {
anatofuz
parents:
diff changeset
212 if (@available(macos 10.12, *))
anatofuz
parents:
diff changeset
213 with_availability_attr<char>();
anatofuz
parents:
diff changeset
214 else
anatofuz
parents:
diff changeset
215 with_availability_attr<int>(); // expected-warning {{'with_availability_attr<int>' is only available on macOS 10.11 or newer}} expected-note {{enclose}}
anatofuz
parents:
diff changeset
216 }
anatofuz
parents:
diff changeset
217
anatofuz
parents:
diff changeset
218 int instantiate_availability() {
anatofuz
parents:
diff changeset
219 if (@available(macOS 10.12, *))
anatofuz
parents:
diff changeset
220 with_availability_attr<int_10_12>();
anatofuz
parents:
diff changeset
221 else
anatofuz
parents:
diff changeset
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}}
anatofuz
parents:
diff changeset
223 }
anatofuz
parents:
diff changeset
224
anatofuz
parents:
diff changeset
225 auto topLevelLambda = [] () {
anatofuz
parents:
diff changeset
226 func_10_12(); // expected-warning{{'func_10_12' is only available on macOS 10.12 or newer}} expected-note{{@available}}
anatofuz
parents:
diff changeset
227 if (@available(macos 10.12, *))
anatofuz
parents:
diff changeset
228 func_10_12();
anatofuz
parents:
diff changeset
229 };
anatofuz
parents:
diff changeset
230
anatofuz
parents:
diff changeset
231 void functionInFunction() {
anatofuz
parents:
diff changeset
232 func_10_12(); // expected-warning{{'func_10_12' is only available on macOS 10.12 or newer}} expected-note{{@available}}
anatofuz
parents:
diff changeset
233 struct DontWarnTwice {
anatofuz
parents:
diff changeset
234 void f() {
anatofuz
parents:
diff changeset
235 func_10_12(); // expected-warning{{'func_10_12' is only available on macOS 10.12 or newer}} expected-note{{@available}}
anatofuz
parents:
diff changeset
236 }
anatofuz
parents:
diff changeset
237 };
anatofuz
parents:
diff changeset
238 void([] () {
anatofuz
parents:
diff changeset
239 func_10_12(); // expected-warning{{'func_10_12' is only available on macOS 10.12 or newer}} expected-note{{@available}}
anatofuz
parents:
diff changeset
240 });
anatofuz
parents:
diff changeset
241 (void)(^ {
anatofuz
parents:
diff changeset
242 func_10_12(); // expected-warning{{'func_10_12' is only available on macOS 10.12 or newer}} expected-note{{@available}}
anatofuz
parents:
diff changeset
243 });
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
244
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
245 if (@available(macos 10.12, *)) {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
246 void([]() {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
247 func_10_12();
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
248 void([] () {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
249 func_10_12();
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
250 });
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
251 struct DontWarn {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
252 void f() {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
253 func_10_12();
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
254 }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
255 };
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
256 });
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
257 }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
258
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
259 if (@available(macos 10.12, *)) {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
260 struct DontWarn {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
261 void f() {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
262 func_10_12();
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
263 void([] () {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
264 func_10_12();
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
265 });
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
266 struct DontWarn2 {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
267 void f() {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
268 func_10_12();
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
269 }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
270 };
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
271 }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
272 };
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
273 }
150
anatofuz
parents:
diff changeset
274 }
anatofuz
parents:
diff changeset
275
anatofuz
parents:
diff changeset
276 #endif
anatofuz
parents:
diff changeset
277
anatofuz
parents:
diff changeset
278 struct InStruct { // expected-note{{annotate 'InStruct' with an availability attribute to silence}}
anatofuz
parents:
diff changeset
279 new_int mem; // expected-warning{{'new_int' is only available on macOS 10.12 or newer}}
anatofuz
parents:
diff changeset
280
anatofuz
parents:
diff changeset
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}}
anatofuz
parents:
diff changeset
282 };
anatofuz
parents:
diff changeset
283
anatofuz
parents:
diff changeset
284 #ifdef OBJCPP
anatofuz
parents:
diff changeset
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.0}}
anatofuz
parents:
diff changeset
286 typedef enum { // expected-note{{annotate anonymous enum with an availability attribute}}
anatofuz
parents:
diff changeset
287 SomeValue = SomeConstexprValue // expected-warning{{'SomeConstexprValue' is only available on macOS 10.12 or newer}}
anatofuz
parents:
diff changeset
288 } SomeEnum;
anatofuz
parents:
diff changeset
289 #endif
anatofuz
parents:
diff changeset
290
anatofuz
parents:
diff changeset
291 @interface InInterface
anatofuz
parents:
diff changeset
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}}
anatofuz
parents:
diff changeset
293 @end
anatofuz
parents:
diff changeset
294
anatofuz
parents:
diff changeset
295 @interface Proper // expected-note{{annotate 'Proper' with an availability attribute}}
anatofuz
parents:
diff changeset
296 @property (class) new_int x; // expected-warning{{'new_int' is only available}}
anatofuz
parents:
diff changeset
297 @end
anatofuz
parents:
diff changeset
298
anatofuz
parents:
diff changeset
299 void with_local_struct() {
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
300 struct local {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
301 new_int x; // expected-warning{{'new_int' is only available}} expected-note{{enclose 'new_int' in an @available check}}
150
anatofuz
parents:
diff changeset
302 };
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
303 if (@available(macos 10.12, *)) {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
304 struct DontWarn {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
305 new_int x;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
306 };
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
307 }
150
anatofuz
parents:
diff changeset
308 }
anatofuz
parents:
diff changeset
309
anatofuz
parents:
diff changeset
310 // rdar://33156429:
anatofuz
parents:
diff changeset
311 // Avoid the warning on protocol requirements.
anatofuz
parents:
diff changeset
312
anatofuz
parents:
diff changeset
313 AVAILABLE_10_12
anatofuz
parents:
diff changeset
314 @protocol NewProtocol // expected-note {{'NewProtocol' has been marked as being introduced in macOS 10.12 here, but the deployment target is macOS 10.9.0}}
anatofuz
parents:
diff changeset
315 @end
anatofuz
parents:
diff changeset
316
anatofuz
parents:
diff changeset
317 @protocol ProtocolWithNewProtocolRequirement <NewProtocol> // expected-note {{annotate 'ProtocolWithNewProtocolRequirement' with an availability attribute to silence}}
anatofuz
parents:
diff changeset
318
anatofuz
parents:
diff changeset
319 @property(copy) id<NewProtocol> prop; // expected-warning {{'NewProtocol' is only available on macOS 10.12 or newer}}
anatofuz
parents:
diff changeset
320
anatofuz
parents:
diff changeset
321 @end
anatofuz
parents:
diff changeset
322
anatofuz
parents:
diff changeset
323 @interface BaseClass
anatofuz
parents:
diff changeset
324 @end
anatofuz
parents:
diff changeset
325
anatofuz
parents:
diff changeset
326 @interface ClassWithNewProtocolRequirement : BaseClass <NewProtocol>
anatofuz
parents:
diff changeset
327
anatofuz
parents:
diff changeset
328 @end
anatofuz
parents:
diff changeset
329
anatofuz
parents:
diff changeset
330 @interface BaseClass (CategoryWithNewProtocolRequirement) <NewProtocol>
anatofuz
parents:
diff changeset
331
anatofuz
parents:
diff changeset
332 @end
anatofuz
parents:
diff changeset
333
anatofuz
parents:
diff changeset
334 typedef enum {
anatofuz
parents:
diff changeset
335 AK_Dodo __attribute__((availability(macos, deprecated=10.3))), // expected-note 3 {{marked deprecated here}}
anatofuz
parents:
diff changeset
336 AK_Cat __attribute__((availability(macos, introduced=10.4))),
anatofuz
parents:
diff changeset
337 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.0}}
anatofuz
parents:
diff changeset
338 } Animals;
anatofuz
parents:
diff changeset
339
anatofuz
parents:
diff changeset
340 void switchAnimals(Animals a) {
anatofuz
parents:
diff changeset
341 switch (a) {
anatofuz
parents:
diff changeset
342 case AK_Dodo: break; // expected-warning{{'AK_Dodo' is deprecated}}
anatofuz
parents:
diff changeset
343 case AK_Cat: break;
anatofuz
parents:
diff changeset
344 case AK_Cat|AK_CyborgCat: break; // expected-warning{{case value not in enum}}
anatofuz
parents:
diff changeset
345 case AK_CyborgCat: break; // no warn
anatofuz
parents:
diff changeset
346 }
anatofuz
parents:
diff changeset
347
anatofuz
parents:
diff changeset
348 switch (a) {
anatofuz
parents:
diff changeset
349 case AK_Dodo...AK_CyborgCat: // expected-warning {{'AK_Dodo' is depr}}
anatofuz
parents:
diff changeset
350 break;
anatofuz
parents:
diff changeset
351 }
anatofuz
parents:
diff changeset
352
anatofuz
parents:
diff changeset
353 (void)AK_Dodo; // expected-warning{{'AK_Dodo' is deprecated}}
anatofuz
parents:
diff changeset
354 (void)AK_Cat; // no warning
anatofuz
parents:
diff changeset
355 (void)AK_CyborgCat; // expected-warning{{'AK_CyborgCat' is only available on macOS 10.12 or newer}} expected-note {{@available}}
anatofuz
parents:
diff changeset
356 }
anatofuz
parents:
diff changeset
357
anatofuz
parents:
diff changeset
358
anatofuz
parents:
diff changeset
359 // test static initializers has the same availability as the deployment target and it cannot be overwritten.
anatofuz
parents:
diff changeset
360 @interface HasStaticInitializer : BaseClass
anatofuz
parents:
diff changeset
361 + (void)load AVAILABLE_10_11; // expected-warning{{ignoring availability attribute on '+load' method}}
anatofuz
parents:
diff changeset
362 @end
anatofuz
parents:
diff changeset
363
anatofuz
parents:
diff changeset
364 @implementation HasStaticInitializer
anatofuz
parents:
diff changeset
365 + (void)load {
anatofuz
parents:
diff changeset
366 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}}
anatofuz
parents:
diff changeset
367 }
anatofuz
parents:
diff changeset
368 @end
anatofuz
parents:
diff changeset
369
anatofuz
parents:
diff changeset
370 // test availability from interface is ignored when checking the unguarded availability in +load method.
anatofuz
parents:
diff changeset
371 AVAILABLE_10_11
anatofuz
parents:
diff changeset
372 @interface HasStaticInitializer1 : BaseClass
anatofuz
parents:
diff changeset
373 + (void)load;
anatofuz
parents:
diff changeset
374 + (void)load: (int)x; // no warning.
anatofuz
parents:
diff changeset
375 @end
anatofuz
parents:
diff changeset
376
anatofuz
parents:
diff changeset
377 @implementation HasStaticInitializer1
anatofuz
parents:
diff changeset
378 + (void)load {
anatofuz
parents:
diff changeset
379 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}}
anatofuz
parents:
diff changeset
380 }
anatofuz
parents:
diff changeset
381 + (void)load: (int)x {
anatofuz
parents:
diff changeset
382 func_10_11(); // no warning.
anatofuz
parents:
diff changeset
383 }
anatofuz
parents:
diff changeset
384 @end
anatofuz
parents:
diff changeset
385
anatofuz
parents:
diff changeset
386 __attribute__((constructor))
anatofuz
parents:
diff changeset
387 void is_constructor();
anatofuz
parents:
diff changeset
388
anatofuz
parents:
diff changeset
389 AVAILABLE_10_11 // expected-warning{{ignoring availability attribute with constructor attribute}}
anatofuz
parents:
diff changeset
390 void is_constructor() {
anatofuz
parents:
diff changeset
391 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}}
anatofuz
parents:
diff changeset
392 }
anatofuz
parents:
diff changeset
393
anatofuz
parents:
diff changeset
394 AVAILABLE_10_11 // expected-warning{{ignoring availability attribute with destructor attribute}}
anatofuz
parents:
diff changeset
395 __attribute__((destructor))
anatofuz
parents:
diff changeset
396 void is_destructor() {
anatofuz
parents:
diff changeset
397 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}}
anatofuz
parents:
diff changeset
398 }