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 // UNSUPPORTED: c++98, c++03 10 // UNSUPPORTED: !libc++ && c++11 11 // UNSUPPORTED: !libc++ && c++14 12 13 // The roundtrip test uses to_chars, which requires functions in the dylib 14 // that were introduced in Mac OS 10.15. 15 // 16 // XFAIL: with_system_cxx_lib=macosx10.14 17 // XFAIL: with_system_cxx_lib=macosx10.13 18 // XFAIL: with_system_cxx_lib=macosx10.12 19 // XFAIL: with_system_cxx_lib=macosx10.11 20 // XFAIL: with_system_cxx_lib=macosx10.10 21 // XFAIL: with_system_cxx_lib=macosx10.9 22 23 // <charconv> 24 25 // from_chars_result from_chars(const char* first, const char* last, 26 // Integral& value, int base = 10) 27 28 #include <charconv> 29 #include "test_macros.h" 30 #include "charconv_test_helpers.h" 31 32 template <typename T> 33 struct test_basics : roundtrip_test_base<T> 34 { 35 using roundtrip_test_base<T>::test; 36 37 void operator()() 38 { 39 test(0); 40 test(42); 41 test(32768); 42 test(0, 10); 43 test(42, 10); 44 test(32768, 10); 45 test(0xf, 16); 46 test(0xdeadbeaf, 16); 47 test(0755, 8); 48 49 for (int b = 2; b < 37; ++b) 50 { 51 using xl = std::numeric_limits<T>; 52 53 test(1, b); 54 test(-1, b); 55 test(xl::lowest(), b); 56 test((xl::max)(), b); 57 test((xl::max)() / 2, b); 58 } 59 } 60 }; 61 62 template <typename T> 63 struct test_signed : roundtrip_test_base<T> 64 { 65 using roundtrip_test_base<T>::test; 66 67 void operator()() 68 { 69 test(-1); 70 test(-12); 71 test(-1, 10); 72 test(-12, 10); 73 test(-21734634, 10); 74 test(-2647, 2); 75 test(-0xcc1, 16); 76 77 for (int b = 2; b < 37; ++b) 78 { 79 using xl = std::numeric_limits<T>; 80 81 test(0, b); 82 test(xl::lowest(), b); 83 test((xl::max)(), b); 84 } 85 } 86 }; 87 88 int main(int, char**) 89 { 90 run<test_basics>(integrals); 91 run<test_signed>(all_signed); 92 93 return 0; 94 } 95