| 1 | // 2003-12-19 Paolo Carlini <[email protected]> |
| 2 | |
| 3 | // Copyright (C) 2003-2025 Free Software Foundation, Inc. |
| 4 | // |
| 5 | // This file is part of the GNU ISO C++ Library. This library is free |
| 6 | // software; you can redistribute it and/or modify it under the |
| 7 | // terms of the GNU General Public License as published by the |
| 8 | // Free Software Foundation; either version 3, or (at your option) |
| 9 | // any later version. |
| 10 | |
| 11 | // This library is distributed in the hope that it will be useful, |
| 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | // GNU General Public License for more details. |
| 15 | |
| 16 | // You should have received a copy of the GNU General Public License along |
| 17 | // with this library; see the file COPYING3. If not see |
| 18 | // <http://www.gnu.org/licenses/>. |
| 19 | |
| 20 | // 22.2.2.1.1 num_get members |
| 21 | |
| 22 | #include <locale> |
| 23 | #include <sstream> |
| 24 | #include <testsuite_hooks.h> |
| 25 | |
| 26 | void test01() |
| 27 | { |
| 28 | using namespace std; |
| 29 | typedef istreambuf_iterator<wchar_t> iterator_type; |
| 30 | |
| 31 | wistringstream iss; |
| 32 | const num_get<wchar_t>& ng = use_facet<num_get<wchar_t> >(iss.getloc()); |
| 33 | ios_base::iostate err = ios_base::goodbit; |
| 34 | iterator_type end; |
| 35 | float f = 1.0f; |
| 36 | double d = 1.0; |
| 37 | long double ld = 1.0l; |
| 38 | |
| 39 | iss.str(L"1e."); |
| 40 | err = ios_base::goodbit; |
| 41 | end = ng.get(iss.rdbuf(), 0, iss, err, f); |
| 42 | VERIFY( err == ios_base::failbit ); |
| 43 | VERIFY( *end == L'.' ); |
| 44 | VERIFY( f == 0.0f ); |
| 45 | |
| 46 | iss.str(L"3e+"); |
| 47 | iss.clear(); |
| 48 | err = ios_base::goodbit; |
| 49 | end = ng.get(iss.rdbuf(), 0, iss, err, d); |
| 50 | VERIFY( err == (ios_base::failbit | ios_base::eofbit) ); |
| 51 | VERIFY( d == 0.0 ); |
| 52 | |
| 53 | iss.str(L"6e "); |
| 54 | iss.clear(); |
| 55 | err = ios_base::goodbit; |
| 56 | end = ng.get(iss.rdbuf(), 0, iss, err, ld); |
| 57 | VERIFY( *end == L' ' ); |
| 58 | |
| 59 | // libstdc++/37624. We can't always obtain the required behavior |
| 60 | // when sscanf is involved, because of, e.g., glibc/1765. |
| 61 | #if defined(_GLIBCXX_HAVE_STRTOLD) && !defined(_GLIBCXX_HAVE_BROKEN_STRTOLD) |
| 62 | VERIFY( err == ios_base::failbit ); |
| 63 | VERIFY( ld == 0.0l ); |
| 64 | #endif |
| 65 | } |
| 66 | |
| 67 | int main() |
| 68 | { |
| 69 | test01(); |
| 70 | return 0; |
| 71 | } |