| 1 |
// { dg-do run { target c++11 } } |
| 2 |
// { dg-require-string-conversions "" } |
| 3 |
|
| 4 |
// 2009-11-11 Paolo Carlini <[email protected]> |
| 5 |
|
| 6 |
// Copyright (C) 2009-2025 Free Software Foundation, Inc. |
| 7 |
// |
| 8 |
// This file is part of the GNU ISO C++ Library. This library is free |
| 9 |
// software; you can redistribute it and/or modify it under the |
| 10 |
// terms of the GNU General Public License as published by the |
| 11 |
// Free Software Foundation; either version 3, or (at your option) |
| 12 |
// any later version. |
| 13 |
// |
| 14 |
// This library is distributed in the hope that it will be useful, |
| 15 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 |
// GNU General Public License for more details. |
| 18 |
// |
| 19 |
// You should have received a copy of the GNU General Public License along |
| 20 |
// with this library; see the file COPYING3. If not see |
| 21 |
// <http://www.gnu.org/licenses/>. |
| 22 |
|
| 23 |
#include <string> |
| 24 |
#include <testsuite_hooks.h> |
| 25 |
|
| 26 |
// DR 1261. Insufficient overloads for to_string / to_wstring |
| 27 |
void test01() |
| 28 |
{ |
| 29 |
using namespace std; |
| 30 |
|
| 31 |
const string one(to_string(-2)); |
| 32 |
VERIFY( one == "-2" ); |
| 33 |
|
| 34 |
const string two(to_string(10u)); |
| 35 |
VERIFY( two == "10" ); |
| 36 |
|
| 37 |
const string three(to_string(2l)); |
| 38 |
VERIFY( three == "2" ); |
| 39 |
|
| 40 |
const string four(to_string(3000ul)); |
| 41 |
VERIFY( four == "3000" ); |
| 42 |
|
| 43 |
const string five(to_string(7ll)); |
| 44 |
VERIFY( five == "7" ); |
| 45 |
|
| 46 |
const string six(to_string(400ull)); |
| 47 |
VERIFY( six == "400" ); |
| 48 |
|
| 49 |
string tail; |
| 50 |
#if __cpp_lib_to_string < 202306L |
| 51 |
tail = ".000000"; |
| 52 |
#endif |
| 53 |
|
| 54 |
const string seven(to_string(-1.0F)); |
| 55 |
VERIFY( seven == "-1" + tail ); |
| 56 |
|
| 57 |
const string eight(to_string(2.0)); |
| 58 |
VERIFY( eight == "2" + tail ); |
| 59 |
|
| 60 |
const string nine(to_string(-4.0L)); |
| 61 |
VERIFY( nine == "-4" + tail ); |
| 62 |
} |
| 63 |
|
| 64 |
int main() |
| 65 |
{ |
| 66 |
test01(); |
| 67 |
return 0; |
| 68 |
} |