1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // XFAIL: with_system_cxx_lib=x86_64-apple-darwin11
11 // XFAIL: with_system_cxx_lib=x86_64-apple-darwin12
12 
13 // <string>
14 
15 // unsigned long long stoull(const string& str, size_t *idx = 0, int base = 10);
16 // unsigned long long stoull(const wstring& str, size_t *idx = 0, int base = 10);
17 
18 #include <string>
19 #include <cassert>
20 
main()21 int main()
22 {
23     assert(std::stoull("0") == 0);
24     assert(std::stoull(L"0") == 0);
25     assert(std::stoull("-0") == 0);
26     assert(std::stoull(L"-0") == 0);
27     assert(std::stoull(" 10") == 10);
28     assert(std::stoull(L" 10") == 10);
29     size_t idx = 0;
30     assert(std::stoull("10g", &idx, 16) == 16);
31     assert(idx == 2);
32     idx = 0;
33     assert(std::stoull(L"10g", &idx, 16) == 16);
34     assert(idx == 2);
35     idx = 0;
36     try
37     {
38         std::stoull("", &idx);
39         assert(false);
40     }
41     catch (const std::invalid_argument&)
42     {
43         assert(idx == 0);
44     }
45     idx = 0;
46     try
47     {
48         std::stoull(L"", &idx);
49         assert(false);
50     }
51     catch (const std::invalid_argument&)
52     {
53         assert(idx == 0);
54     }
55     try
56     {
57         std::stoull("  - 8", &idx);
58         assert(false);
59     }
60     catch (const std::invalid_argument&)
61     {
62         assert(idx == 0);
63     }
64     try
65     {
66         std::stoull(L"  - 8", &idx);
67         assert(false);
68     }
69     catch (const std::invalid_argument&)
70     {
71         assert(idx == 0);
72     }
73     try
74     {
75         std::stoull("a1", &idx);
76         assert(false);
77     }
78     catch (const std::invalid_argument&)
79     {
80         assert(idx == 0);
81     }
82     try
83     {
84         std::stoull(L"a1", &idx);
85         assert(false);
86     }
87     catch (const std::invalid_argument&)
88     {
89         assert(idx == 0);
90     }
91 //  LWG issue #2009
92     try
93     {
94         std::stoull("9999999999999999999999999999999999999999999999999", &idx);
95         assert(false);
96     }
97     catch (const std::out_of_range&)
98     {
99         assert(idx == 0);
100     }
101     try
102     {
103         std::stoull(L"9999999999999999999999999999999999999999999999999", &idx);
104         assert(false);
105     }
106     catch (const std::out_of_range&)
107     {
108         assert(idx == 0);
109     }
110 }
111