blob: bc55f009e0a8b2dfcfb93d83b29238eff29e2c99 [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001//===----------------------------------------------------------------------===//
2//
Howard Hinnantf5256e12010-05-11 21:36:01 +00003// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00005// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00007//
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
Marshall Clow83e2c4d2013-01-05 03:21:01 +000020#include "platform_support.h" // locale name macros
Howard Hinnantc0d0cba2011-10-03 15:23:59 +000021
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000022typedef std::codecvt_byname<wchar_t, char, std::mbstate_t> F;
23
24class my_facet
25 : public F
26{
27public:
28 static int count;
29
30 explicit my_facet(const char* nm, std::size_t refs = 0)
31 : F(nm, refs) {++count;}
32 explicit my_facet(const std::string& nm, std::size_t refs = 0)
33 : F(nm, refs) {++count;}
34
35 ~my_facet() {--count;}
36};
37
38int my_facet::count = 0;
39
40int main()
41{
42 {
Howard Hinnantc0d0cba2011-10-03 15:23:59 +000043 std::locale l(std::locale::classic(), new my_facet(LOCALE_en_US_UTF_8));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000044 assert(my_facet::count == 1);
45 }
46 assert(my_facet::count == 0);
47 {
Howard Hinnantc0d0cba2011-10-03 15:23:59 +000048 my_facet f(LOCALE_en_US_UTF_8, 1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000049 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 {
Howard Hinnantc0d0cba2011-10-03 15:23:59 +000058 std::locale l(std::locale::classic(), new my_facet(std::string(LOCALE_en_US_UTF_8)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000059 assert(my_facet::count == 1);
60 }
61 assert(my_facet::count == 0);
62 {
Howard Hinnantc0d0cba2011-10-03 15:23:59 +000063 my_facet f(std::string(LOCALE_en_US_UTF_8), 1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000064 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}