76 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 11// XFAIL: availability-char8_t_support-missing12 13// This test runs in C++20, but we have deprecated codecvt<char(16|32), char, mbstate_t> in C++20.14// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS15 16// <locale>17 18// static const locale& classic();19 20#include <locale>21#include <cassert>22 23#include "test_macros.h"24#include "platform_support.h" // locale name macros25 26template<class CharT>27void check_for(const std::locale& loc)28{29 assert(std::has_facet<std::collate<CharT> >(loc));30 31 assert(std::has_facet<std::ctype<CharT> >(loc));32 33 assert((std::has_facet<std::codecvt<CharT, char, std::mbstate_t> >(loc)));34 35 assert(std::has_facet<std::moneypunct<CharT> >(loc));36 assert(std::has_facet<std::money_get<CharT> >(loc));37 assert(std::has_facet<std::money_put<CharT> >(loc));38 39 assert(std::has_facet<std::numpunct<CharT> >(loc));40 assert(std::has_facet<std::num_get<CharT> >(loc));41 assert(std::has_facet<std::num_put<CharT> >(loc));42 43 assert(std::has_facet<std::time_get<CharT> >(loc));44 assert(std::has_facet<std::time_put<CharT> >(loc));45 46 assert(std::has_facet<std::messages<CharT> >(loc));47}48 49void check(const std::locale& loc)50{51 check_for<char>(loc);52#ifndef TEST_HAS_NO_WIDE_CHARACTERS53 check_for<wchar_t>(loc);54#endif55 56 assert((std::has_facet<std::codecvt<char16_t, char, std::mbstate_t> >(loc)));57 assert((std::has_facet<std::codecvt<char32_t, char, std::mbstate_t> >(loc)));58#if TEST_STD_VER > 1759 assert((std::has_facet<std::codecvt<char16_t, char8_t, std::mbstate_t> >(loc)));60 assert((std::has_facet<std::codecvt<char32_t, char8_t, std::mbstate_t> >(loc)));61#endif62}63 64int main(int, char**)65{66 std::locale loc;67 assert(loc.name() == "C");68 check(loc);69 assert(std::locale::global(std::locale(LOCALE_en_US_UTF_8)) == loc);70 std::locale loc2;71 check(loc2);72 assert(loc2 == std::locale(LOCALE_en_US_UTF_8));73 74 return 0;75}76