brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.8 KiB · beeba43 Raw
100 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.ru_RU.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// template <class Facet> locale(const locale& other, Facet* f);19 20#include <locale>21#include <new>22#include <cassert>23 24#include "count_new.h"25#include "test_macros.h"26#include "platform_support.h" // locale name macros27 28 29template<class CharT>30void check_for(const std::locale& loc)31{32    assert(std::has_facet<std::collate<CharT> >(loc));33 34    assert(std::has_facet<std::ctype<CharT> >(loc));35 36    assert((std::has_facet<std::codecvt<CharT, char, std::mbstate_t> >(loc)));37 38    assert(std::has_facet<std::moneypunct<CharT> >(loc));39    assert(std::has_facet<std::money_get<CharT> >(loc));40    assert(std::has_facet<std::money_put<CharT> >(loc));41 42    assert(std::has_facet<std::numpunct<CharT> >(loc));43    assert(std::has_facet<std::num_get<CharT> >(loc));44    assert(std::has_facet<std::num_put<CharT> >(loc));45 46    assert(std::has_facet<std::time_get<CharT> >(loc));47    assert(std::has_facet<std::time_put<CharT> >(loc));48 49    assert(std::has_facet<std::messages<CharT> >(loc));50}51 52void check(const std::locale& loc)53{54    check_for<char>(loc);55#ifndef TEST_HAS_NO_WIDE_CHARACTERS56    check_for<wchar_t>(loc);57#endif58 59    assert((std::has_facet<std::codecvt<char16_t, char, std::mbstate_t> >(loc)));60    assert((std::has_facet<std::codecvt<char32_t, char, std::mbstate_t> >(loc)));61#if TEST_STD_VER > 1762    assert((std::has_facet<std::codecvt<char16_t, char8_t, std::mbstate_t> >(loc)));63    assert((std::has_facet<std::codecvt<char32_t, char8_t, std::mbstate_t> >(loc)));64#endif65}66 67struct my_facet68    : public std::locale::facet69{70    int test() const {return 5;}71 72    static std::locale::id id;73};74 75std::locale::id my_facet::id;76 77int main(int, char**)78{79    {80        std::locale loc(LOCALE_ru_RU_UTF_8);81        check(loc);82        std::locale loc2(loc, new my_facet);83        check(loc2);84        assert((std::has_facet<my_facet>(loc2)));85        const my_facet& f = std::use_facet<my_facet>(loc2);86        assert(f.test() == 5);87    }88    assert(globalMemCounter.checkOutstandingNewEq(0));89    {90        std::locale loc;91        check(loc);92        std::locale loc2(loc, (std::ctype<char>*)0);93        check(loc2);94        assert(loc == loc2);95    }96    assert(globalMemCounter.checkOutstandingNewEq(0));97 98  return 0;99}100