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 | //===----------------------------------------------------------------------===// |
8 | |
9 | // XFAIL: availability-char8_t_support-missing |
10 | |
11 | // This test runs in C++20, but we have deprecated codecvt<char(16|32), char, mbstate_t> in C++20. |
12 | // ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS |
13 | |
14 | // <locale> |
15 | |
16 | // static const locale& classic(); |
17 | |
18 | #include <locale> |
19 | #include <cassert> |
20 | |
21 | #include "test_macros.h" |
22 | |
23 | template<class CharT> |
24 | void check_for(const std::locale& loc) |
25 | { |
26 | assert(std::has_facet<std::collate<CharT> >(loc)); |
27 | |
28 | assert(std::has_facet<std::ctype<CharT> >(loc)); |
29 | |
30 | assert((std::has_facet<std::codecvt<CharT, char, std::mbstate_t> >(loc))); |
31 | |
32 | assert(std::has_facet<std::moneypunct<CharT> >(loc)); |
33 | assert(std::has_facet<std::money_get<CharT> >(loc)); |
34 | assert(std::has_facet<std::money_put<CharT> >(loc)); |
35 | |
36 | assert(std::has_facet<std::numpunct<CharT> >(loc)); |
37 | assert(std::has_facet<std::num_get<CharT> >(loc)); |
38 | assert(std::has_facet<std::num_put<CharT> >(loc)); |
39 | |
40 | assert(std::has_facet<std::time_get<CharT> >(loc)); |
41 | assert(std::has_facet<std::time_put<CharT> >(loc)); |
42 | |
43 | assert(std::has_facet<std::messages<CharT> >(loc)); |
44 | } |
45 | |
46 | void check(const std::locale& loc) |
47 | { |
48 | check_for<char>(loc); |
49 | #ifndef TEST_HAS_NO_WIDE_CHARACTERS |
50 | check_for<wchar_t>(loc); |
51 | #endif |
52 | |
53 | assert((std::has_facet<std::codecvt<char16_t, char, std::mbstate_t> >(loc))); |
54 | assert((std::has_facet<std::codecvt<char32_t, char, std::mbstate_t> >(loc))); |
55 | #if TEST_STD_VER > 17 |
56 | assert((std::has_facet<std::codecvt<char16_t, char8_t, std::mbstate_t> >(loc))); |
57 | assert((std::has_facet<std::codecvt<char32_t, char8_t, std::mbstate_t> >(loc))); |
58 | #endif |
59 | } |
60 | |
61 | int main(int, char**) |
62 | { |
63 | std::locale loc = std::locale::classic(); |
64 | assert(loc.name() == "C" ); |
65 | assert(loc == std::locale("C" )); |
66 | check(loc); |
67 | check(loc: std::locale("C" )); |
68 | |
69 | return 0; |
70 | } |
71 | |