[libstdc++][testsuite] XFAIL tests relying on long double-to-string conversions on...
[official-gcc.git] / libstdc++-v3 / testsuite / 21_strings / basic_string / numeric_conversions / char / stod.cc
blob088641130075add8346948f286cfc63de6637721
1 // { dg-do run { target c++11 } }
2 // { dg-require-string-conversions "" }
3 // { dg-xfail-run-if "broken long double IO" { newlib_broken_long_double_io } "*" "" }
5 // 2008-06-15 Paolo Carlini <paolo.carlini@oracle.com>
7 // Copyright (C) 2008-2016 Free Software Foundation, Inc.
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
12 // Free Software Foundation; either version 3, or (at your option)
13 // any later version.
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.
20 // You should have received a copy of the GNU General Public License along
21 // with this library; see the file COPYING3. If not see
22 // <http://www.gnu.org/licenses/>.
24 // 21.4 Numeric Conversions [string.conversions]
26 #include <string>
27 #include <limits>
28 #include <stdexcept>
29 #include <testsuite_hooks.h>
31 void
32 test01()
34 bool test = false;
36 using namespace std;
38 try
40 string one;
41 stod(one);
43 catch(std::invalid_argument)
45 test = true;
47 catch(...)
50 VERIFY( test );
52 test = false;
53 try
55 string one("a");
56 stod(one);
58 catch(std::invalid_argument)
60 test = true;
62 catch(...)
65 VERIFY( test );
67 double d1 = 0.0;
68 size_t idx1 = 0;
69 try
71 string one("2.0a");
72 d1 = stod(one, &idx1);
74 catch(...)
76 test = false;
78 VERIFY( test );
79 VERIFY( d1 == 2.0 );
80 VERIFY( idx1 == 3 );
82 test = false;
83 try
85 string one("1e");
86 one.append(2 * numeric_limits<double>::max_exponent10, '9');
87 d1 = stod(one);
89 catch(std::out_of_range)
91 test = true;
93 catch(...)
96 VERIFY( test );
97 VERIFY( d1 == 2.0 );
99 try
101 long double ld0 = numeric_limits<double>::max() / 100.0;
102 string one(to_string(ld0));
103 stod(one);
105 catch(...)
107 test = false;
109 VERIFY( test );
111 if ((numeric_limits<long double>::max() / 10000.0L)
112 > numeric_limits<double>::max())
114 test = false;
115 d1 = -1.0;
118 long double ld1 = numeric_limits<double>::max();
119 ld1 *= 100.0;
120 string one(to_string(ld1));
121 d1 = stod(one);
123 catch(std::out_of_range)
125 test = true;
127 catch(...)
130 VERIFY( test );
131 VERIFY( d1 == -1.0 );
135 int main()
137 test01();
138 return 0;