Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / std / localization / locales / locale.convenience / conversions / conversions.string / converted.pass.cpp
blob2861e4a52036efd8d47f07f67ef22f27fba15ff6
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 //===----------------------------------------------------------------------===//
9 // <locale>
11 // ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS
13 // wstring_convert<Codecvt, Elem, Wide_alloc, Byte_alloc>
15 // size_t converted() const;
17 // XFAIL: no-wide-characters
19 #include <locale>
20 #include <codecvt>
21 #include <cassert>
23 #include "test_macros.h"
25 template <class CharT, std::size_t = sizeof(CharT)>
26 struct TestHelper;
27 template <class CharT>
28 struct TestHelper<CharT, 2> {
29 static void test();
31 template <class CharT>
32 struct TestHelper<CharT, 4> {
33 static void test();
36 template <class CharT>
37 void TestHelper<CharT, 2>::test() {
38 static_assert((std::is_same<CharT, wchar_t>::value), "");
40 typedef std::codecvt_utf8<CharT> Codecvt;
41 typedef std::wstring_convert<Codecvt> Myconv;
42 Myconv myconv;
43 assert(myconv.converted() == 0);
44 std::string bs = myconv.to_bytes(L"\u1005");
45 assert(myconv.converted() == 1);
46 bs = myconv.to_bytes(L"\u1005e");
47 assert(myconv.converted() == 2);
48 std::wstring ws = myconv.from_bytes("\xE1\x80\x85");
49 assert(myconv.converted() == 3);
53 template <class CharT>
54 void TestHelper<CharT, 4>::test() {
55 static_assert((std::is_same<CharT, wchar_t>::value), "");
57 typedef std::codecvt_utf8<CharT> Codecvt;
58 typedef std::wstring_convert<Codecvt> Myconv;
59 Myconv myconv;
60 assert(myconv.converted() == 0);
61 std::string bs = myconv.to_bytes(L"\U00040003");
62 assert(myconv.converted() == 1);
63 bs = myconv.to_bytes(L"\U00040003e");
64 assert(myconv.converted() == 2);
65 std::wstring ws = myconv.from_bytes("\xF1\x80\x80\x83");
66 assert(myconv.converted() == 4);
70 int main(int, char**) {
71 TestHelper<wchar_t>::test();
72 return 0;