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 stoul(const string& str, size_t *idx = 0, int base = 10);
16// unsigned long stoul(const wstring& str, size_t *idx = 0, int base = 10);
17
18#include <string>
19#include <cassert>
20
21int main()
22{
23    assert(std::stoul("0") == 0);
24    assert(std::stoul(L"0") == 0);
25    assert(std::stoul("-0") == 0);
26    assert(std::stoul(L"-0") == 0);
27    assert(std::stoul(" 10") == 10);
28    assert(std::stoul(L" 10") == 10);
29    size_t idx = 0;
30    assert(std::stoul("10g", &idx, 16) == 16);
31    assert(idx == 2);
32    idx = 0;
33    assert(std::stoul(L"10g", &idx, 16) == 16);
34    assert(idx == 2);
35    idx = 0;
36    try
37    {
38        std::stoul("", &idx);
39        assert(false);
40    }
41    catch (const std::invalid_argument&)
42    {
43        assert(idx == 0);
44    }
45    try
46    {
47        std::stoul(L"", &idx);
48        assert(false);
49    }
50    catch (const std::invalid_argument&)
51    {
52        assert(idx == 0);
53    }
54    try
55    {
56        std::stoul("  - 8", &idx);
57        assert(false);
58    }
59    catch (const std::invalid_argument&)
60    {
61        assert(idx == 0);
62    }
63    try
64    {
65        std::stoul(L"  - 8", &idx);
66        assert(false);
67    }
68    catch (const std::invalid_argument&)
69    {
70        assert(idx == 0);
71    }
72    try
73    {
74        std::stoul("a1", &idx);
75        assert(false);
76    }
77    catch (const std::invalid_argument&)
78    {
79        assert(idx == 0);
80    }
81    try
82    {
83        std::stoul(L"a1", &idx);
84        assert(false);
85    }
86    catch (const std::invalid_argument&)
87    {
88        assert(idx == 0);
89    }
90//  LWG issue #2009
91    try
92    {
93        std::stoul("9999999999999999999999999999999999999999999999999", &idx);
94        assert(false);
95    }
96    catch (const std::out_of_range&)
97    {
98        assert(idx == 0);
99    }
100    try
101    {
102        std::stoul(L"9999999999999999999999999999999999999999999999999", &idx);
103        assert(false);
104    }
105    catch (const std::out_of_range&)
106    {
107        assert(idx == 0);
108    }
109}
110