80 lines · cpp
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9// REQUIRES: locale.en_US.UTF-810// REQUIRES: locale.ru_RU.UTF-811// UNSUPPORTED: sanitizer-new-delete12 13// XFAIL: availability-char8_t_support-missing14 15// This test runs in C++20, but we have deprecated codecvt<char(16|32), char, mbstate_t> in C++20.16// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS17 18// <locale>19 20// locale(const locale& other, const string& std_name, category cat);21 22#include <locale>23#include <new>24#include <cassert>25 26#include "count_new.h"27#include "test_macros.h"28#include "platform_support.h" // locale name macros29 30template<class CharT>31void check_for(const std::locale& loc)32{33 assert(std::has_facet<std::collate<CharT> >(loc));34 35 assert(std::has_facet<std::ctype<CharT> >(loc));36 37 assert((std::has_facet<std::codecvt<CharT, char, std::mbstate_t> >(loc)));38 39 assert(std::has_facet<std::moneypunct<CharT> >(loc));40 assert(std::has_facet<std::money_get<CharT> >(loc));41 assert(std::has_facet<std::money_put<CharT> >(loc));42 43 assert(std::has_facet<std::numpunct<CharT> >(loc));44 assert(std::has_facet<std::num_get<CharT> >(loc));45 assert(std::has_facet<std::num_put<CharT> >(loc));46 47 assert(std::has_facet<std::time_get<CharT> >(loc));48 assert(std::has_facet<std::time_put<CharT> >(loc));49 50 assert(std::has_facet<std::messages<CharT> >(loc));51}52 53void check(const std::locale& loc)54{55 check_for<char>(loc);56#ifndef TEST_HAS_NO_WIDE_CHARACTERS57 check_for<wchar_t>(loc);58#endif59 60 assert((std::has_facet<std::codecvt<char16_t, char, std::mbstate_t> >(loc)));61 assert((std::has_facet<std::codecvt<char32_t, char, std::mbstate_t> >(loc)));62#if TEST_STD_VER > 1763 assert((std::has_facet<std::codecvt<char16_t, char8_t, std::mbstate_t> >(loc)));64 assert((std::has_facet<std::codecvt<char32_t, char8_t, std::mbstate_t> >(loc)));65#endif66}67 68int main(int, char**)69{70 {71 std::locale loc(LOCALE_ru_RU_UTF_8);72 check(loc);73 std::locale loc2(loc, std::string(LOCALE_en_US_UTF_8), std::locale::monetary);74 check(loc2);75 }76 assert(globalMemCounter.checkOutstandingNewEq(0));77 78 return 0;79}80