| 1 |
// Copyright (C) 2009-2025 Free Software Foundation, Inc. |
| 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 |
|
| 18 |
// 22.2.2.1.1 num_get members |
| 19 |
|
| 20 |
#include <locale> |
| 21 |
#include <sstream> |
| 22 |
#include <limits> |
| 23 |
#include <testsuite_hooks.h> |
| 24 |
|
| 25 |
// libstdc++/39802 |
| 26 |
void test01() |
| 27 |
{ |
| 28 |
using namespace std; |
| 29 |
typedef istreambuf_iterator<char> iterator_type; |
| 30 |
|
| 31 |
stringstream ss; |
| 32 |
const num_get<char>& ng = use_facet<num_get<char> >(ss.getloc()); |
| 33 |
ios_base::iostate err; |
| 34 |
iterator_type end; |
| 35 |
const string empty; |
| 36 |
|
| 37 |
unsigned long ul0 = 1; |
| 38 |
const unsigned long ul1 = numeric_limits<unsigned long>::max(); |
| 39 |
|
| 40 |
ss << "-0"; |
| 41 |
err = ios_base::goodbit; |
| 42 |
end = ng.get(ss.rdbuf(), 0, ss, err, ul0); |
| 43 |
VERIFY( err == ios_base::eofbit ); |
| 44 |
VERIFY( ul0 == 0 ); |
| 45 |
|
| 46 |
ss.clear(); |
| 47 |
ss.str(empty); |
| 48 |
ss << "-1"; |
| 49 |
err = ios_base::goodbit; |
| 50 |
end = ng.get(ss.rdbuf(), 0, ss, err, ul0); |
| 51 |
VERIFY( err == ios_base::eofbit ); |
| 52 |
VERIFY( ul0 == ul1 ); |
| 53 |
|
| 54 |
ss.clear(); |
| 55 |
ss.str(empty); |
| 56 |
ss << '-' << ul1; |
| 57 |
err = ios_base::goodbit; |
| 58 |
end = ng.get(ss.rdbuf(), 0, ss, err, ul0); |
| 59 |
VERIFY( err == ios_base::eofbit ); |
| 60 |
VERIFY( ul0 == 1 ); |
| 61 |
|
| 62 |
ss.clear(); |
| 63 |
ss.str(empty); |
| 64 |
ss << '-' << ul1 << '0'; |
| 65 |
err = ios_base::goodbit; |
| 66 |
end = ng.get(ss.rdbuf(), 0, ss, err, ul0); |
| 67 |
VERIFY( err == (ios_base::eofbit | ios_base::failbit) ); |
| 68 |
VERIFY( ul0 == ul1 ); |
| 69 |
} |
| 70 |
|
| 71 |
int main() |
| 72 |
{ |
| 73 |
test01(); |
| 74 |
return 0; |
| 75 |
} |