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// <locale>
10
11// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS -D_LIBCPP_ENABLE_CXX26_REMOVED_CODECVT -D_LIBCPP_ENABLE_CXX26_REMOVED_WSTRING_CONVERT
12
13// wstring_convert<Codecvt, Elem, Wide_alloc, Byte_alloc>
14
15// wstring_convert(const byte_string& byte_err,
16// const wide_string& wide_err = wide_string());
17
18// XFAIL: no-wide-characters
19
20#include <cassert>
21#include <codecvt>
22#include <locale>
23#include <type_traits>
24
25#include "test_macros.h"
26
27int main(int, char**)
28{
29 typedef std::codecvt_utf8<wchar_t> Codecvt;
30 typedef std::wstring_convert<Codecvt> Myconv;
31#if TEST_STD_VER > 11
32 static_assert(!std::is_convertible<std::string, Myconv>::value, "");
33 static_assert( std::is_constructible<Myconv, std::string>::value, "");
34#endif
35#ifndef TEST_HAS_NO_EXCEPTIONS
36 {
37 Myconv myconv;
38 try
39 {
40 TEST_IGNORE_NODISCARD myconv.to_bytes(L"\xDA83");
41 assert(false);
42 }
43 catch (const std::range_error&)
44 {
45 }
46 try
47 {
48 TEST_IGNORE_NODISCARD myconv.from_bytes('\xA5');
49 assert(false);
50 }
51 catch (const std::range_error&)
52 {
53 }
54 }
55#endif
56 {
57 Myconv myconv("byte error");
58 std::string bs = myconv.to_bytes(L"\xDA83");
59 assert(bs == "byte error");
60#ifndef TEST_HAS_NO_EXCEPTIONS
61 try
62 {
63 TEST_IGNORE_NODISCARD myconv.from_bytes('\xA5');
64 assert(false);
65 }
66 catch (const std::range_error&)
67 {
68 }
69#endif
70 }
71 {
72 Myconv myconv("byte error", L"wide error");
73 std::string bs = myconv.to_bytes(L"\xDA83");
74 assert(bs == "byte error");
75 std::wstring ws = myconv.from_bytes('\xA5');
76 assert(ws == L"wide error");
77 }
78
79 return 0;
80}
81

source code of libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.string/ctor_err_string.pass.cpp