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 // REQUIRES: locale.ru_RU.UTF-8
10 // REQUIRES: locale.zh_CN.UTF-8
11
12 // This test relies on https://wg21.link/P0482 being implemented, which isn't in
13 // older Apple dylibs
14 // XFAIL: use_system_cxx_lib && target={{.+}}-apple-macosx{{10.9|10.10|10.11|10.12|10.13|10.14|10.15|11.0}}
15
16 // This test runs in C++20, but we have deprecated codecvt<char(16|32), char, mbstate_t> in C++20.
17 // ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS
18
19 // <locale>
20
21 // explicit locale(const string& std_name);
22
23 #include <locale>
24 #include <new>
25 #include <cassert>
26
27 #include "count_new.h"
28 #include "test_macros.h"
29 #include "platform_support.h" // locale name macros
30
31 template<class CharT>
check_for(const std::locale & loc)32 void check_for(const std::locale& loc)
33 {
34 assert(std::has_facet<std::collate<CharT> >(loc));
35
36 assert(std::has_facet<std::ctype<CharT> >(loc));
37
38 assert((std::has_facet<std::codecvt<CharT, char, std::mbstate_t> >(loc)));
39
40 assert(std::has_facet<std::moneypunct<CharT> >(loc));
41 assert(std::has_facet<std::money_get<CharT> >(loc));
42 assert(std::has_facet<std::money_put<CharT> >(loc));
43
44 assert(std::has_facet<std::numpunct<CharT> >(loc));
45 assert(std::has_facet<std::num_get<CharT> >(loc));
46 assert(std::has_facet<std::num_put<CharT> >(loc));
47
48 assert(std::has_facet<std::time_get<CharT> >(loc));
49 assert(std::has_facet<std::time_put<CharT> >(loc));
50
51 assert(std::has_facet<std::messages<CharT> >(loc));
52 }
53
check(const std::locale & loc)54 void check(const std::locale& loc)
55 {
56 check_for<char>(loc);
57 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
58 check_for<wchar_t>(loc);
59 #endif
60
61 assert((std::has_facet<std::codecvt<char16_t, char, std::mbstate_t> >(loc)));
62 assert((std::has_facet<std::codecvt<char32_t, char, std::mbstate_t> >(loc)));
63 #if TEST_STD_VER > 17
64 assert((std::has_facet<std::codecvt<char16_t, char8_t, std::mbstate_t> >(loc)));
65 assert((std::has_facet<std::codecvt<char32_t, char8_t, std::mbstate_t> >(loc)));
66 #endif
67 }
68
main(int,char **)69 int main(int, char**)
70 {
71 {
72 std::locale loc(std::string(LOCALE_ru_RU_UTF_8));
73 check(loc);
74 std::locale loc2(std::string(LOCALE_ru_RU_UTF_8));
75 check(loc2);
76 assert(loc == loc2);
77 std::locale loc3(std::string(LOCALE_zh_CN_UTF_8));
78 check(loc3);
79 assert(!(loc == loc3));
80 assert(loc != loc3);
81 }
82 assert(globalMemCounter.checkOutstandingNewEq(0));
83
84 return 0;
85 }
86