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 // <locale>
11 
12 // template <> class codecvt_byname<wchar_t, char, mbstate_t>
13 
14 // explicit codecvt_byname(const char* nm, size_t refs = 0);
15 // explicit codecvt_byname(const string& nm, size_t refs = 0);
16 
17 #include <locale>
18 #include <cassert>
19 
20 #include "platform_support.h" // locale name macros
21 
22 typedef std::codecvt_byname<wchar_t, char, std::mbstate_t> F;
23 
24 class my_facet
25     : public F
26 {
27 public:
28     static int count;
29 
my_facet(const char * nm,std::size_t refs=0)30     explicit my_facet(const char* nm, std::size_t refs = 0)
31         : F(nm, refs) {++count;}
my_facet(const std::string & nm,std::size_t refs=0)32     explicit my_facet(const std::string& nm, std::size_t refs = 0)
33         : F(nm, refs) {++count;}
34 
~my_facet()35     ~my_facet() {--count;}
36 };
37 
38 int my_facet::count = 0;
39 
main()40 int main()
41 {
42     {
43         std::locale l(std::locale::classic(), new my_facet(LOCALE_en_US_UTF_8));
44         assert(my_facet::count == 1);
45     }
46     assert(my_facet::count == 0);
47     {
48         my_facet f(LOCALE_en_US_UTF_8, 1);
49         assert(my_facet::count == 1);
50         {
51             std::locale l(std::locale::classic(), &f);
52             assert(my_facet::count == 1);
53         }
54         assert(my_facet::count == 1);
55     }
56     assert(my_facet::count == 0);
57     {
58         std::locale l(std::locale::classic(), new my_facet(std::string(LOCALE_en_US_UTF_8)));
59         assert(my_facet::count == 1);
60     }
61     assert(my_facet::count == 0);
62     {
63         my_facet f(std::string(LOCALE_en_US_UTF_8), 1);
64         assert(my_facet::count == 1);
65         {
66             std::locale l(std::locale::classic(), &f);
67             assert(my_facet::count == 1);
68         }
69         assert(my_facet::count == 1);
70     }
71     assert(my_facet::count == 0);
72 }
73