]>
Commit | Line | Data |
---|---|---|
83ffe9cd | 1 | // Copyright (C) 2019-2023 Free Software Foundation, Inc. |
28f00757 JW |
2 | // |
3 | // This file is part of the GNU ISO C++ Library. This library is free | |
4 | // software; you can redistribute it and/or modify it under the | |
5 | // terms of the GNU General Public License as published by the | |
6 | // Free Software Foundation; either version 3, or (at your option) | |
7 | // any later version. | |
8 | ||
9 | // This library is distributed in the hope that it will be useful, | |
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | // GNU General Public License for more details. | |
13 | ||
14 | // You should have received a copy of the GNU General Public License along | |
15 | // with this library; see the file COPYING3. If not see | |
16 | // <http://www.gnu.org/licenses/>. | |
17 | ||
28f00757 JW |
18 | // { dg-do run { target c++17 } } |
19 | // { dg-require-string-conversions "" } | |
20 | ||
21 | #include <charconv> | |
22 | #include <string_view> | |
23 | #include <testsuite_hooks.h> | |
24 | ||
25 | template<typename C> | |
26 | bool | |
27 | check_to_chars(C val) | |
28 | { | |
29 | using std::string_view; | |
30 | ||
31 | char buf1[32], buf2[32], buf3[32]; | |
32 | std::to_chars_result r1 = std::to_chars(buf1, buf1+sizeof(buf1), val); | |
33 | if (r1.ec != std::errc{}) | |
34 | return false; | |
35 | std::to_chars_result r2 = std::to_chars(buf2, buf2+sizeof(buf2), val, 10); | |
36 | if (r2.ec != std::errc{}) | |
37 | return false; | |
38 | if (string_view(buf1, r1.ptr - buf1) != string_view(buf2, r2.ptr - buf2)) | |
39 | return false; | |
40 | std::to_chars_result r3 = std::to_chars(buf3, buf3+sizeof(buf3), (long)val); | |
41 | if (string_view(buf1, r1.ptr - buf1) != string_view(buf3, r3.ptr - buf3)) | |
42 | return false; | |
43 | return true; | |
44 | } | |
45 | ||
46 | void | |
47 | test01() | |
48 | { | |
49 | VERIFY( check_to_chars(u'\x21') ); | |
50 | VERIFY( check_to_chars(U'\x21') ); | |
28f00757 | 51 | VERIFY( check_to_chars(L'\x21') ); |
28f00757 JW |
52 | } |
53 | ||
54 | int main() | |
55 | { | |
56 | test01(); | |
57 | } |