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