1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 // REQUIRES: locale.ru_RU.UTF-8
11 // UNSUPPORTED: sanitizer-new-delete
12 
13 // <locale>
14 
15 // locale(const locale& other, const string& std_name, category cat);
16 
17 #include <locale>
18 #include <new>
19 #include <cassert>
20 
21 #include "platform_support.h" // locale name macros
22 
23 int new_called = 0;
24 
operator new(std::size_t s)25 void* operator new(std::size_t s) throw(std::bad_alloc)
26 {
27     ++new_called;
28     return std::malloc(s);
29 }
30 
operator delete(void * p)31 void  operator delete(void* p) throw()
32 {
33     --new_called;
34     std::free(p);
35 }
36 
check(const std::locale & loc)37 void check(const std::locale& loc)
38 {
39     assert(std::has_facet<std::collate<char> >(loc));
40     assert(std::has_facet<std::collate<wchar_t> >(loc));
41 
42     assert(std::has_facet<std::ctype<char> >(loc));
43     assert(std::has_facet<std::ctype<wchar_t> >(loc));
44     assert((std::has_facet<std::codecvt<char, char, std::mbstate_t> >(loc)));
45     assert((std::has_facet<std::codecvt<char16_t, char, std::mbstate_t> >(loc)));
46     assert((std::has_facet<std::codecvt<char32_t, char, std::mbstate_t> >(loc)));
47     assert((std::has_facet<std::codecvt<wchar_t, char, std::mbstate_t> >(loc)));
48 
49     assert((std::has_facet<std::moneypunct<char> >(loc)));
50     assert((std::has_facet<std::moneypunct<wchar_t> >(loc)));
51     assert((std::has_facet<std::money_get<char> >(loc)));
52     assert((std::has_facet<std::money_get<wchar_t> >(loc)));
53     assert((std::has_facet<std::money_put<char> >(loc)));
54     assert((std::has_facet<std::money_put<wchar_t> >(loc)));
55 
56     assert((std::has_facet<std::numpunct<char> >(loc)));
57     assert((std::has_facet<std::numpunct<wchar_t> >(loc)));
58     assert((std::has_facet<std::num_get<char> >(loc)));
59     assert((std::has_facet<std::num_get<wchar_t> >(loc)));
60     assert((std::has_facet<std::num_put<char> >(loc)));
61     assert((std::has_facet<std::num_put<wchar_t> >(loc)));
62 
63     assert((std::has_facet<std::time_get<char> >(loc)));
64     assert((std::has_facet<std::time_get<wchar_t> >(loc)));
65     assert((std::has_facet<std::time_put<char> >(loc)));
66     assert((std::has_facet<std::time_put<wchar_t> >(loc)));
67 
68     assert((std::has_facet<std::messages<char> >(loc)));
69     assert((std::has_facet<std::messages<wchar_t> >(loc)));
70 }
71 
main()72 int main()
73 {
74     {
75         std::locale loc(LOCALE_ru_RU_UTF_8);
76         check(loc);
77         std::locale loc2(loc, std::string(LOCALE_en_US_UTF_8), std::locale::monetary);
78         check(loc2);
79     }
80     assert(new_called == 0);
81 }
82