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 12 // <locale> 13 14 // template <class Facet> locale(const locale& other, Facet* f); 15 16 #include <locale> 17 #include <new> 18 #include <cassert> 19 20 #include "count_new.hpp" 21 #include "platform_support.h" // locale name macros 22 23 24 void check(const std::locale& loc) 25 { 26 assert(std::has_facet<std::collate<char> >(loc)); 27 assert(std::has_facet<std::collate<wchar_t> >(loc)); 28 29 assert(std::has_facet<std::ctype<char> >(loc)); 30 assert(std::has_facet<std::ctype<wchar_t> >(loc)); 31 assert((std::has_facet<std::codecvt<char, char, std::mbstate_t> >(loc))); 32 assert((std::has_facet<std::codecvt<char16_t, char, std::mbstate_t> >(loc))); 33 assert((std::has_facet<std::codecvt<char32_t, char, std::mbstate_t> >(loc))); 34 assert((std::has_facet<std::codecvt<wchar_t, char, std::mbstate_t> >(loc))); 35 36 assert((std::has_facet<std::moneypunct<char> >(loc))); 37 assert((std::has_facet<std::moneypunct<wchar_t> >(loc))); 38 assert((std::has_facet<std::money_get<char> >(loc))); 39 assert((std::has_facet<std::money_get<wchar_t> >(loc))); 40 assert((std::has_facet<std::money_put<char> >(loc))); 41 assert((std::has_facet<std::money_put<wchar_t> >(loc))); 42 43 assert((std::has_facet<std::numpunct<char> >(loc))); 44 assert((std::has_facet<std::numpunct<wchar_t> >(loc))); 45 assert((std::has_facet<std::num_get<char> >(loc))); 46 assert((std::has_facet<std::num_get<wchar_t> >(loc))); 47 assert((std::has_facet<std::num_put<char> >(loc))); 48 assert((std::has_facet<std::num_put<wchar_t> >(loc))); 49 50 assert((std::has_facet<std::time_get<char> >(loc))); 51 assert((std::has_facet<std::time_get<wchar_t> >(loc))); 52 assert((std::has_facet<std::time_put<char> >(loc))); 53 assert((std::has_facet<std::time_put<wchar_t> >(loc))); 54 55 assert((std::has_facet<std::messages<char> >(loc))); 56 assert((std::has_facet<std::messages<wchar_t> >(loc))); 57 } 58 59 struct my_facet 60 : public std::locale::facet 61 { 62 int test() const {return 5;} 63 64 static std::locale::id id; 65 }; 66 67 std::locale::id my_facet::id; 68 69 int main() 70 { 71 { 72 std::locale loc(LOCALE_ru_RU_UTF_8); 73 check(loc); 74 std::locale loc2(loc, new my_facet); 75 check(loc2); 76 assert((std::has_facet<my_facet>(loc2))); 77 const my_facet& f = std::use_facet<my_facet>(loc2); 78 assert(f.test() == 5); 79 } 80 assert(globalMemCounter.checkOutstandingNewEq(0)); 81 { 82 std::locale loc; 83 check(loc); 84 std::locale loc2(loc, (std::ctype<char>*)0); 85 check(loc2); 86 assert(loc == loc2); 87 } 88 assert(globalMemCounter.checkOutstandingNewEq(0)); 89 } 90