]>
Commit | Line | Data |
---|---|---|
52066eae | 1 | // { dg-do run { target c++11 } } |
aded0ed0 | 2 | // { dg-require-string-conversions "" } |
4f4b0ab8 | 3 | // { dg-xfail-run-if "broken long double IO" { newlib_broken_long_double_io } } |
39c42937 | 4 | |
7364f286 PC |
5 | // 2008-06-15 Paolo Carlini <paolo.carlini@oracle.com> |
6 | ||
a945c346 | 7 | // Copyright (C) 2008-2024 Free Software Foundation, Inc. |
7364f286 PC |
8 | // |
9 | // This file is part of the GNU ISO C++ Library. This library is free | |
10 | // software; you can redistribute it and/or modify it under the | |
11 | // terms of the GNU General Public License as published by the | |
748086b7 | 12 | // Free Software Foundation; either version 3, or (at your option) |
7364f286 PC |
13 | // any later version. |
14 | ||
15 | // This library is distributed in the hope that it will be useful, | |
16 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 | // GNU General Public License for more details. | |
19 | ||
20 | // You should have received a copy of the GNU General Public License along | |
748086b7 JJ |
21 | // with this library; see the file COPYING3. If not see |
22 | // <http://www.gnu.org/licenses/>. | |
7364f286 PC |
23 | |
24 | // 21.4 Numeric Conversions [string.conversions] | |
25 | ||
26 | #include <string> | |
27 | #include <limits> | |
28 | #include <stdexcept> | |
29 | #include <testsuite_hooks.h> | |
30 | ||
31 | void | |
32 | test01() | |
33 | { | |
23c64853 | 34 | #if _GLIBCXX_USE_C99_WCHAR |
7364f286 | 35 | |
118c8424 | 36 | bool test = false; |
7364f286 PC |
37 | using namespace std; |
38 | ||
39 | try | |
40 | { | |
41 | wstring one; | |
13feb023 | 42 | stold(one); |
7364f286 | 43 | } |
13feb023 | 44 | catch(const std::invalid_argument&) |
7364f286 PC |
45 | { |
46 | test = true; | |
47 | } | |
48 | catch(...) | |
49 | { | |
50 | } | |
51 | VERIFY( test ); | |
52 | ||
53 | test = false; | |
54 | try | |
55 | { | |
56 | wstring one(L"a"); | |
13feb023 | 57 | stold(one); |
7364f286 | 58 | } |
13feb023 | 59 | catch(const std::invalid_argument&) |
7364f286 PC |
60 | { |
61 | test = true; | |
62 | } | |
63 | catch(...) | |
64 | { | |
65 | } | |
66 | VERIFY( test ); | |
67 | ||
68 | long double ld1 = 0.0L; | |
69 | size_t idx1 = 0; | |
70 | try | |
71 | { | |
72 | wstring one(L"2.0a"); | |
13feb023 | 73 | ld1 = stold(one, &idx1); |
7364f286 PC |
74 | } |
75 | catch(...) | |
76 | { | |
77 | test = false; | |
78 | } | |
79 | VERIFY( test ); | |
80 | VERIFY( ld1 == 2.0L ); | |
81 | VERIFY( idx1 == 3 ); | |
82 | ||
83 | test = false; | |
84 | try | |
85 | { | |
86 | wstring one(L"1e"); | |
87 | one.append(2 * numeric_limits<long double>::max_exponent10, L'9'); | |
88 | ld1 = stold(one); | |
89 | } | |
13feb023 | 90 | catch(const std::out_of_range&) |
7364f286 PC |
91 | { |
92 | test = true; | |
93 | } | |
94 | catch(...) | |
95 | { | |
96 | } | |
97 | VERIFY( test ); | |
98 | VERIFY( ld1 == 2.0L ); | |
99 | ||
100 | try | |
101 | { | |
102 | long double ld0 = numeric_limits<long double>::max() / 100.0L; | |
103 | wstring one(to_wstring(ld0)); | |
104 | stold(one); | |
105 | } | |
106 | catch(...) | |
107 | { | |
108 | test = false; | |
109 | } | |
110 | VERIFY( test ); | |
111 | ||
112 | #endif | |
113 | } | |
114 | ||
115 | int main() | |
116 | { | |
117 | test01(); | |
118 | return 0; | |
119 | } |