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