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-exception
6//
7//===----------------------------------------------------------------------===//
8
9// REQUIRES: locale.en_US.UTF-8
10
11// XFAIL: availability-char8_t_support-missing
12
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_WARNINGS
15
16// <locale>
17
18// locale() throw();
19
20#include <locale>
21#include <cassert>
22
23#include "test_macros.h"
24#include "platform_support.h" // locale name macros
25#include "count_new.h"
26
27template<class CharT>
28void check_for(const std::locale& loc)
29{
30 assert(std::has_facet<std::collate<CharT> >(loc));
31
32 assert(std::has_facet<std::ctype<CharT> >(loc));
33
34 assert((std::has_facet<std::codecvt<CharT, char, std::mbstate_t> >(loc)));
35
36 assert(std::has_facet<std::moneypunct<CharT> >(loc));
37 assert(std::has_facet<std::money_get<CharT> >(loc));
38 assert(std::has_facet<std::money_put<CharT> >(loc));
39
40 assert(std::has_facet<std::numpunct<CharT> >(loc));
41 assert(std::has_facet<std::num_get<CharT> >(loc));
42 assert(std::has_facet<std::num_put<CharT> >(loc));
43
44 assert(std::has_facet<std::time_get<CharT> >(loc));
45 assert(std::has_facet<std::time_put<CharT> >(loc));
46
47 assert(std::has_facet<std::messages<CharT> >(loc));
48}
49
50void check(const std::locale& loc)
51{
52 check_for<char>(loc);
53#ifndef TEST_HAS_NO_WIDE_CHARACTERS
54 check_for<wchar_t>(loc);
55#endif
56
57 assert((std::has_facet<std::codecvt<char16_t, char, std::mbstate_t> >(loc)));
58 assert((std::has_facet<std::codecvt<char32_t, char, std::mbstate_t> >(loc)));
59#if TEST_STD_VER > 17
60 assert((std::has_facet<std::codecvt<char16_t, char8_t, std::mbstate_t> >(loc)));
61 assert((std::has_facet<std::codecvt<char32_t, char8_t, std::mbstate_t> >(loc)));
62#endif
63}
64
65int main(int, char**)
66{
67 int ok;
68 {
69 std::locale loc;
70 assert(globalMemCounter.checkOutstandingNewEq(0));
71 assert(loc.name() == "C");
72 assert(globalMemCounter.checkOutstandingNewEq(0));
73 check(loc);
74 assert(globalMemCounter.checkOutstandingNewEq(0));
75 assert(std::locale::global(std::locale(LOCALE_en_US_UTF_8)) == loc);
76 ok = globalMemCounter.outstanding_new;
77 std::locale loc2;
78 assert(globalMemCounter.checkOutstandingNewEq(ok));
79 check(loc: loc2);
80 assert(globalMemCounter.checkOutstandingNewEq(ok));
81 assert(loc2 == std::locale(LOCALE_en_US_UTF_8));
82 assert(globalMemCounter.checkOutstandingNewEq(ok));
83 }
84 assert(globalMemCounter.checkOutstandingNewEq(ok));
85
86 return 0;
87}
88

source code of libcxx/test/std/localization/locales/locale/locale.cons/default.pass.cpp