• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
11 // This test relies on P0482 being fixed, which isn't in
12 // older Apple dylibs
13 //
14 // XFAIL: with_system_cxx_lib=macosx10.15
15 // XFAIL: with_system_cxx_lib=macosx10.14
16 // XFAIL: with_system_cxx_lib=macosx10.13
17 // XFAIL: with_system_cxx_lib=macosx10.12
18 // XFAIL: with_system_cxx_lib=macosx10.11
19 // XFAIL: with_system_cxx_lib=macosx10.10
20 // XFAIL: with_system_cxx_lib=macosx10.9
21 
22 // This test runs in C++20, but we have deprecated codecvt<char(16|32), char, mbstate_t> in C++20.
23 // ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS
24 
25 // <locale>
26 
27 // template <class Facet> locale(const locale& other, Facet* f);
28 
29 #include <locale>
30 #include <new>
31 #include <cassert>
32 
33 #include "count_new.h"
34 #include "test_macros.h"
35 #include "platform_support.h" // locale name macros
36 
37 
check(const std::locale & loc)38 void check(const std::locale& loc)
39 {
40     assert(std::has_facet<std::collate<char> >(loc));
41     assert(std::has_facet<std::collate<wchar_t> >(loc));
42 
43     assert(std::has_facet<std::ctype<char> >(loc));
44     assert(std::has_facet<std::ctype<wchar_t> >(loc));
45     assert((std::has_facet<std::codecvt<char, char, std::mbstate_t> >(loc)));
46     assert((std::has_facet<std::codecvt<char16_t, char, std::mbstate_t> >(loc)));
47     assert((std::has_facet<std::codecvt<char32_t, char, std::mbstate_t> >(loc)));
48 #if TEST_STD_VER > 17
49     assert((std::has_facet<std::codecvt<char16_t, char8_t, std::mbstate_t> >(loc)));
50     assert((std::has_facet<std::codecvt<char32_t, char8_t, std::mbstate_t> >(loc)));
51 #endif
52     assert((std::has_facet<std::codecvt<wchar_t, char, std::mbstate_t> >(loc)));
53 
54     assert((std::has_facet<std::moneypunct<char> >(loc)));
55     assert((std::has_facet<std::moneypunct<wchar_t> >(loc)));
56     assert((std::has_facet<std::money_get<char> >(loc)));
57     assert((std::has_facet<std::money_get<wchar_t> >(loc)));
58     assert((std::has_facet<std::money_put<char> >(loc)));
59     assert((std::has_facet<std::money_put<wchar_t> >(loc)));
60 
61     assert((std::has_facet<std::numpunct<char> >(loc)));
62     assert((std::has_facet<std::numpunct<wchar_t> >(loc)));
63     assert((std::has_facet<std::num_get<char> >(loc)));
64     assert((std::has_facet<std::num_get<wchar_t> >(loc)));
65     assert((std::has_facet<std::num_put<char> >(loc)));
66     assert((std::has_facet<std::num_put<wchar_t> >(loc)));
67 
68     assert((std::has_facet<std::time_get<char> >(loc)));
69     assert((std::has_facet<std::time_get<wchar_t> >(loc)));
70     assert((std::has_facet<std::time_put<char> >(loc)));
71     assert((std::has_facet<std::time_put<wchar_t> >(loc)));
72 
73     assert((std::has_facet<std::messages<char> >(loc)));
74     assert((std::has_facet<std::messages<wchar_t> >(loc)));
75 }
76 
77 struct my_facet
78     : public std::locale::facet
79 {
testmy_facet80     int test() const {return 5;}
81 
82     static std::locale::id id;
83 };
84 
85 std::locale::id my_facet::id;
86 
main(int,char **)87 int main(int, char**)
88 {
89     {
90         std::locale loc(LOCALE_ru_RU_UTF_8);
91         check(loc);
92         std::locale loc2(loc, new my_facet);
93         check(loc2);
94         assert((std::has_facet<my_facet>(loc2)));
95         const my_facet& f = std::use_facet<my_facet>(loc2);
96         assert(f.test() == 5);
97     }
98     assert(globalMemCounter.checkOutstandingNewEq(0));
99     {
100         std::locale loc;
101         check(loc);
102         std::locale loc2(loc, (std::ctype<char>*)0);
103         check(loc2);
104         assert(loc == loc2);
105     }
106     assert(globalMemCounter.checkOutstandingNewEq(0));
107 
108   return 0;
109 }
110