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