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 // <string>
10 
11 // template<> struct char_traits<char32_t>
12 
13 // static size_t length(const char_type* s);
14 // constexpr in C++17
15 
16 #include <string>
17 #include <cassert>
18 
19 #include "test_macros.h"
20 
21 #if TEST_STD_VER > 14
test_constexpr()22 constexpr bool test_constexpr()
23 {
24     return std::char_traits<char32_t>::length(U"") == 0
25         && std::char_traits<char32_t>::length(U"abcd") == 4;
26 }
27 #endif
28 
main(int,char **)29 int main(int, char**)
30 {
31 #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
32 #if TEST_STD_VER >= 11
33     assert(std::char_traits<char32_t>::length(U"") == 0);
34     assert(std::char_traits<char32_t>::length(U"a") == 1);
35     assert(std::char_traits<char32_t>::length(U"aa") == 2);
36     assert(std::char_traits<char32_t>::length(U"aaa") == 3);
37     assert(std::char_traits<char32_t>::length(U"aaaa") == 4);
38 #endif
39 
40 #if TEST_STD_VER > 14
41     static_assert(test_constexpr(), "" );
42 #endif
43 #endif  // _LIBCPP_HAS_NO_UNICODE_CHARS
44 
45   return 0;
46 }
47