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  } }
4 
5 // 2008-06-15  Paolo Carlini  <paolo.carlini@oracle.com>
6 
7 // Copyright (C) 2008-2018 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.
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
21 // with this library; see the file COPYING3.  If not see
22 // <http://www.gnu.org/licenses/>.
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
test01()32 test01()
33 {
34 #if _GLIBCXX_USE_C99_WCHAR
35 
36   bool test = false;
37   using namespace std;
38 
39   try
40     {
41       wstring one;
42       stold(one);
43     }
44   catch(std::invalid_argument)
45     {
46       test = true;
47     }
48   catch(...)
49     {
50     }
51   VERIFY( test );
52 
53   test = false;
54   try
55     {
56       wstring one(L"a");
57       stold(one);
58     }
59   catch(std::invalid_argument)
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");
73       ld1 = stold(one, &idx1);
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     }
90   catch(std::out_of_range)
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 
main()115 int main()
116 {
117   test01();
118   return 0;
119 }
120