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 // <codecvt>
10
11 // ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS -D_LIBCPP_ENABLE_CXX26_REMOVED_CODECVT
12
13 // template <class Elem, unsigned long Maxcode = 0x10ffff,
14 // codecvt_mode Mode = (codecvt_mode)0>
15 // class codecvt_utf8
16 // : public codecvt<Elem, char, mbstate_t>
17 // {
18 // // unspecified
19 // };
20
21 // int max_length() const throw();
22
23 #include <codecvt>
24 #include <cassert>
25
26 #include "test_macros.h"
27
28 template <class CharT, std::size_t = sizeof(CharT)>
29 struct TestHelper;
30
31 template <class CharT>
32 struct TestHelper<CharT, 2> {
33 static void test();
34 };
35
36 template <class CharT>
37 struct TestHelper<CharT, 4> {
38 static void test();
39 };
40
41 template <class CharT>
test()42 void TestHelper<CharT, 2>::test() {
43 {
44 typedef std::codecvt_utf8<CharT> C;
45 C c;
46 int r = c.max_length();
47 assert(r == 3);
48 }
49 {
50 typedef std::codecvt_utf8<CharT, 0xFFFFFFFF, std::consume_header> C;
51 C c;
52 int r = c.max_length();
53 assert(r == 6);
54 }
55 }
56
57 template <class CharT>
test()58 void TestHelper<CharT, 4>::test() {
59 {
60 typedef std::codecvt_utf8<CharT> C;
61 C c;
62 int r = c.max_length();
63 assert(r == 4);
64 }
65 {
66 typedef std::codecvt_utf8<CharT, 0xFFFFFFFF, std::consume_header> C;
67 C c;
68 int r = c.max_length();
69 assert(r == 7);
70 }
71 }
72
main(int,char **)73 int main(int, char**) {
74 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
75 TestHelper<wchar_t>::test();
76 #endif
77 TestHelper<char16_t>::test();
78 TestHelper<char32_t>::test();
79 return 0;
80 }
81