[Clang/AMDGPU] Zero sized arrays not allowed in HIP device code. (#113470)
[llvm-project.git] / libcxx / test / std / localization / locale.stdcvt / codecvt_utf8_in.pass.cpp
blob7f56bc0073ad90e664ceb70057be7ebc42c9b3f5
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 // <codecvt>
11 // ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS -D_LIBCPP_ENABLE_CXX26_REMOVED_CODECVT
13 // template <class Elem, unsigned long Maxcode = 0x10ffff,
14 // codecvt_mode Mode = (codecvt_mode)0>
15 // class codecvt_utf8
16 // : public codecvt<Elem, char, mbstate_t>
17 // {
18 // // unspecified
19 // };
21 // result
22 // in(stateT& state,
23 // const externT* from, const externT* from_end, const externT*& from_next,
24 // internT* to, internT* to_end, internT*& to_next) const;
26 #include <codecvt>
27 #include <cassert>
29 #include "test_macros.h"
31 int main(int, char**)
34 typedef std::codecvt_utf8<char32_t> C;
35 C c;
36 char32_t w = 0;
37 char n[4] = {char(0xF1), char(0x80), char(0x80), char(0x83)};
38 char32_t* wp = nullptr;
39 std::mbstate_t m;
40 const char* np = nullptr;
41 std::codecvt_base::result r = c.in(m, n, n+4, np, &w, &w+1, wp);
42 assert(r == std::codecvt_base::ok);
43 assert(wp == &w+1);
44 assert(np == n+4);
45 assert(w == 0x40003);
47 n[0] = char(0xE1);
48 n[1] = char(0x80);
49 n[2] = char(0x85);
50 r = c.in(m, n, n+3, np, &w, &w+1, wp);
51 assert(r == std::codecvt_base::ok);
52 assert(wp == &w+1);
53 assert(np == n+3);
54 assert(w == 0x1005);
56 n[0] = char(0xD1);
57 n[1] = char(0x93);
58 r = c.in(m, n, n+2, np, &w, &w+1, wp);
59 assert(r == std::codecvt_base::ok);
60 assert(wp == &w+1);
61 assert(np == n+2);
62 assert(w == 0x453);
64 w = 0x56;
65 n[0] = char(0x56);
66 r = c.in(m, n, n+1, np, &w, &w+1, wp);
67 assert(r == std::codecvt_base::ok);
68 assert(wp == &w+1);
69 assert(np == n+1);
70 assert(w == 0x56);
73 typedef std::codecvt_utf8<char32_t, 0x1000> C;
74 C c;
75 char32_t w = 0;
76 char n[4] = {char(0xF1), char(0x80), char(0x80), char(0x83)};
77 char32_t* wp = nullptr;
78 std::mbstate_t m;
79 const char* np = nullptr;
80 std::codecvt_base::result r = c.in(m, n, n+4, np, &w, &w+1, wp);
81 assert(r == std::codecvt_base::error);
82 assert(wp == &w);
83 assert(np == n);
84 assert(w == 0);
86 n[0] = char(0xE1);
87 n[1] = char(0x80);
88 n[2] = char(0x85);
89 r = c.in(m, n, n+3, np, &w, &w+1, wp);
90 assert(r == std::codecvt_base::error);
91 assert(wp == &w);
92 assert(np == n);
93 assert(w == 0);
95 n[0] = char(0xD1);
96 n[1] = char(0x93);
97 r = c.in(m, n, n+2, np, &w, &w+1, wp);
98 assert(r == std::codecvt_base::ok);
99 assert(wp == &w+1);
100 assert(np == n+2);
101 assert(w == 0x453);
103 w = 0x56;
104 n[0] = char(0x56);
105 r = c.in(m, n, n+1, np, &w, &w+1, wp);
106 assert(r == std::codecvt_base::ok);
107 assert(wp == &w+1);
108 assert(np == n+1);
109 assert(w == 0x56);
112 typedef std::codecvt_utf8<char32_t, 0xFFFFFFFF, std::consume_header> C;
113 C c;
114 char32_t w = 0;
115 char n[7] = {char(0xEF), char(0xBB), char(0xBF), char(0xF1), char(0x80), char(0x80), char(0x83)};
116 char32_t* wp = nullptr;
117 std::mbstate_t m;
118 const char* np = nullptr;
119 std::codecvt_base::result r = c.in(m, n, n+7, np, &w, &w+1, wp);
120 assert(r == std::codecvt_base::ok);
121 assert(wp == &w+1);
122 assert(np == n+7);
123 assert(w == 0x40003);
125 n[0] = char(0xE1);
126 n[1] = char(0x80);
127 n[2] = char(0x85);
128 r = c.in(m, n, n+3, np, &w, &w+1, wp);
129 assert(r == std::codecvt_base::ok);
130 assert(wp == &w+1);
131 assert(np == n+3);
132 assert(w == 0x1005);
134 n[0] = char(0xEF);
135 n[1] = char(0xBB);
136 n[2] = char(0xBF);
137 n[3] = char(0xD1);
138 n[4] = char(0x93);
139 r = c.in(m, n, n+5, np, &w, &w+1, wp);
140 assert(r == std::codecvt_base::ok);
141 assert(wp == &w+1);
142 assert(np == n+5);
143 assert(w == 0x453);
145 w = 0x56;
146 n[0] = char(0x56);
147 r = c.in(m, n, n+1, np, &w, &w+1, wp);
148 assert(r == std::codecvt_base::ok);
149 assert(wp == &w+1);
150 assert(np == n+1);
151 assert(w == 0x56);
154 typedef std::codecvt_utf8<char32_t> C;
155 C c;
156 char32_t w = 0;
157 char n[4] = {char(0xF1), char(0x80), char(0x80), char(0x83)};
158 char32_t* wp = nullptr;
159 std::mbstate_t m;
160 const char* np = nullptr;
161 std::codecvt_base::result r = c.in(m, n, n+4, np, &w, &w+1, wp);
162 assert(r == std::codecvt_base::ok);
163 assert(wp == &w+1);
164 assert(np == n+4);
165 assert(w == 0x40003);
167 n[0] = char(0xE1);
168 n[1] = char(0x80);
169 n[2] = char(0x85);
170 r = c.in(m, n, n+3, np, &w, &w+1, wp);
171 assert(r == std::codecvt_base::ok);
172 assert(wp == &w+1);
173 assert(np == n+3);
174 assert(w == 0x1005);
176 n[0] = char(0xD1);
177 n[1] = char(0x93);
178 r = c.in(m, n, n+2, np, &w, &w+1, wp);
179 assert(r == std::codecvt_base::ok);
180 assert(wp == &w+1);
181 assert(np == n+2);
182 assert(w == 0x453);
184 w = 0x56;
185 n[0] = char(0x56);
186 r = c.in(m, n, n+1, np, &w, &w+1, wp);
187 assert(r == std::codecvt_base::ok);
188 assert(wp == &w+1);
189 assert(np == n+1);
190 assert(w == 0x56);
193 typedef std::codecvt_utf8<char32_t, 0x1000> C;
194 C c;
195 char32_t w = 0;
196 char n[4] = {char(0xF1), char(0x80), char(0x80), char(0x83)};
197 char32_t* wp = nullptr;
198 std::mbstate_t m;
199 const char* np = nullptr;
200 std::codecvt_base::result r = c.in(m, n, n+4, np, &w, &w+1, wp);
201 assert(r == std::codecvt_base::error);
202 assert(wp == &w);
203 assert(np == n);
204 assert(w == 0);
206 n[0] = char(0xE1);
207 n[1] = char(0x80);
208 n[2] = char(0x85);
209 r = c.in(m, n, n+3, np, &w, &w+1, wp);
210 assert(r == std::codecvt_base::error);
211 assert(wp == &w);
212 assert(np == n);
213 assert(w == 0);
215 n[0] = char(0xD1);
216 n[1] = char(0x93);
217 r = c.in(m, n, n+2, np, &w, &w+1, wp);
218 assert(r == std::codecvt_base::ok);
219 assert(wp == &w+1);
220 assert(np == n+2);
221 assert(w == 0x453);
223 w = 0x56;
224 n[0] = char(0x56);
225 r = c.in(m, n, n+1, np, &w, &w+1, wp);
226 assert(r == std::codecvt_base::ok);
227 assert(wp == &w+1);
228 assert(np == n+1);
229 assert(w == 0x56);
232 typedef std::codecvt_utf8<char32_t, 0xFFFFFFFF, std::consume_header> C;
233 C c;
234 char32_t w = 0;
235 char n[7] = {char(0xEF), char(0xBB), char(0xBF), char(0xF1), char(0x80), char(0x80), char(0x83)};
236 char32_t* wp = nullptr;
237 std::mbstate_t m;
238 const char* np = nullptr;
239 std::codecvt_base::result r = c.in(m, n, n+7, np, &w, &w+1, wp);
240 assert(r == std::codecvt_base::ok);
241 assert(wp == &w+1);
242 assert(np == n+7);
243 assert(w == 0x40003);
245 n[0] = char(0xE1);
246 n[1] = char(0x80);
247 n[2] = char(0x85);
248 r = c.in(m, n, n+3, np, &w, &w+1, wp);
249 assert(r == std::codecvt_base::ok);
250 assert(wp == &w+1);
251 assert(np == n+3);
252 assert(w == 0x1005);
254 n[0] = char(0xEF);
255 n[1] = char(0xBB);
256 n[2] = char(0xBF);
257 n[3] = char(0xD1);
258 n[4] = char(0x93);
259 r = c.in(m, n, n+5, np, &w, &w+1, wp);
260 assert(r == std::codecvt_base::ok);
261 assert(wp == &w+1);
262 assert(np == n+5);
263 assert(w == 0x453);
265 w = 0x56;
266 n[0] = char(0x56);
267 r = c.in(m, n, n+1, np, &w, &w+1, wp);
268 assert(r == std::codecvt_base::ok);
269 assert(wp == &w+1);
270 assert(np == n+1);
271 assert(w == 0x56);
274 typedef std::codecvt_utf8<char16_t> C;
275 C c;
276 char16_t w = 0;
277 char n[3] = {char(0xE1), char(0x80), char(0x85)};
278 char16_t* wp = nullptr;
279 std::mbstate_t m;
280 const char* np = nullptr;
281 std::codecvt_base::result r = c.in(m, n, n+3, np, &w, &w+1, wp);
282 assert(r == std::codecvt_base::ok);
283 assert(wp == &w+1);
284 assert(np == n+3);
285 assert(w == 0x1005);
287 n[0] = char(0xD1);
288 n[1] = char(0x93);
289 r = c.in(m, n, n+2, np, &w, &w+1, wp);
290 assert(r == std::codecvt_base::ok);
291 assert(wp == &w+1);
292 assert(np == n+2);
293 assert(w == 0x453);
295 w = 0x56;
296 n[0] = char(0x56);
297 r = c.in(m, n, n+1, np, &w, &w+1, wp);
298 assert(r == std::codecvt_base::ok);
299 assert(wp == &w+1);
300 assert(np == n+1);
301 assert(w == 0x56);
304 typedef std::codecvt_utf8<char16_t, 0x1000> C;
305 C c;
306 char16_t w = 0;
307 char n[3] = {char(0xE1), char(0x80), char(0x85)};
308 char16_t* wp = nullptr;
309 std::mbstate_t m;
310 const char* np = nullptr;
311 std::codecvt_base::result r = c.in(m, n, n+3, np, &w, &w+1, wp);
312 assert(r == std::codecvt_base::error);
313 assert(wp == &w);
314 assert(np == n);
315 assert(w == 0);
317 n[0] = char(0xD1);
318 n[1] = char(0x93);
319 r = c.in(m, n, n+2, np, &w, &w+1, wp);
320 assert(r == std::codecvt_base::ok);
321 assert(wp == &w+1);
322 assert(np == n+2);
323 assert(w == 0x453);
325 w = 0x56;
326 n[0] = char(0x56);
327 r = c.in(m, n, n+1, np, &w, &w+1, wp);
328 assert(r == std::codecvt_base::ok);
329 assert(wp == &w+1);
330 assert(np == n+1);
331 assert(w == 0x56);
334 typedef std::codecvt_utf8<char16_t, 0xFFFFFFFF, std::consume_header> C;
335 C c;
336 char16_t w = 0;
337 char n[6] = {char(0xEF), char(0xBB), char(0xBF), char(0xE1), char(0x80), char(0x85)};
338 char16_t* wp = nullptr;
339 std::mbstate_t m;
340 const char* np = nullptr;
341 std::codecvt_base::result r = c.in(m, n, n+6, np, &w, &w+1, wp);
342 assert(r == std::codecvt_base::ok);
343 assert(wp == &w+1);
344 assert(np == n+6);
345 assert(w == 0x1005);
347 n[0] = char(0xD1);
348 n[1] = char(0x93);
349 r = c.in(m, n, n+2, np, &w, &w+1, wp);
350 assert(r == std::codecvt_base::ok);
351 assert(wp == &w+1);
352 assert(np == n+2);
353 assert(w == 0x453);
355 w = 0x56;
356 n[0] = char(0x56);
357 r = c.in(m, n, n+1, np, &w, &w+1, wp);
358 assert(r == std::codecvt_base::ok);
359 assert(wp == &w+1);
360 assert(np == n+1);
361 assert(w == 0x56);
364 return 0;