//===----------------------------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // REQUIRES: locale.ru_RU.UTF-8 // XFAIL: availability-char8_t_support-missing // This test runs in C++20, but we have deprecated codecvt in C++20. // ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS // // template locale(const locale& other, Facet* f); #include #include #include #include "count_new.h" #include "test_macros.h" #include "platform_support.h" // locale name macros template void check_for(const std::locale& loc) { assert(std::has_facet >(loc)); assert(std::has_facet >(loc)); assert((std::has_facet >(loc))); assert(std::has_facet >(loc)); assert(std::has_facet >(loc)); assert(std::has_facet >(loc)); assert(std::has_facet >(loc)); assert(std::has_facet >(loc)); assert(std::has_facet >(loc)); assert(std::has_facet >(loc)); assert(std::has_facet >(loc)); assert(std::has_facet >(loc)); } void check(const std::locale& loc) { check_for(loc); #ifndef TEST_HAS_NO_WIDE_CHARACTERS check_for(loc); #endif assert((std::has_facet >(loc))); assert((std::has_facet >(loc))); #if TEST_STD_VER > 17 assert((std::has_facet >(loc))); assert((std::has_facet >(loc))); #endif } struct my_facet : public std::locale::facet { int test() const {return 5;} static std::locale::id id; }; std::locale::id my_facet::id; int main(int, char**) { { std::locale loc(LOCALE_ru_RU_UTF_8); check(loc); std::locale loc2(loc, new my_facet); check(loc2); assert((std::has_facet(loc2))); const my_facet& f = std::use_facet(loc2); assert(f.test() == 5); } assert(globalMemCounter.checkOutstandingNewEq(0)); { std::locale loc; check(loc); std::locale loc2(loc, (std::ctype*)0); check(loc2); assert(loc == loc2); } assert(globalMemCounter.checkOutstandingNewEq(0)); return 0; }