]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/wchar_t/stod.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 21_strings / basic_string / numeric_conversions / wchar_t / stod.cc
CommitLineData
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
99dee823 7// Copyright (C) 2008-2021 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
31void
32test01()
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 stod(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 stod(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 double d1 = 0.0;
69 size_t idx1 = 0;
70 try
71 {
72 wstring one(L"2.0a");
13feb023 73 d1 = stod(one, &idx1);
7364f286
PC
74 }
75 catch(...)
76 {
77 test = false;
78 }
79 VERIFY( test );
80 VERIFY( d1 == 2.0 );
81 VERIFY( idx1 == 3 );
82
83 test = false;
84 try
85 {
86 wstring one(L"1e");
87 one.append(2 * numeric_limits<double>::max_exponent10, L'9');
88 d1 = stod(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( d1 == 2.0 );
99
100 try
101 {
102 long double ld0 = numeric_limits<double>::max() / 100.0;
103 wstring one(to_wstring(ld0));
104 stod(one);
105 }
106 catch(...)
107 {
108 test = false;
109 }
110 VERIFY( test );
111
5d13614a
PC
112 if ((numeric_limits<long double>::max() / 10000.0L)
113 > numeric_limits<double>::max())
7364f286
PC
114 {
115 test = false;
116 d1 = -1.0;
117 try
118 {
119 long double ld1 = numeric_limits<double>::max();
120 ld1 *= 100.0;
121 wstring one(to_wstring(ld1));
122 d1 = stod(one);
123 }
13feb023 124 catch(const std::out_of_range&)
7364f286
PC
125 {
126 test = true;
127 }
128 catch(...)
129 {
130 }
131 VERIFY( test );
132 VERIFY( d1 == -1.0 );
133 }
134
135#endif
136}
137
138int main()
139{
140 test01();
141 return 0;
142}