1a6a062df66fe49704bd074464af30bf8c3db6ea5Howard Hinnant//===----------------------------------------------------------------------===//
2a6a062df66fe49704bd074464af30bf8c3db6ea5Howard Hinnant//
3a6a062df66fe49704bd074464af30bf8c3db6ea5Howard Hinnant//                     The LLVM Compiler Infrastructure
4a6a062df66fe49704bd074464af30bf8c3db6ea5Howard Hinnant//
5b64f8b07c104c6cc986570ac8ee0ed16a9f23976Howard Hinnant// This file is dual licensed under the MIT and the University of Illinois Open
6b64f8b07c104c6cc986570ac8ee0ed16a9f23976Howard Hinnant// Source Licenses. See LICENSE.TXT for details.
7a6a062df66fe49704bd074464af30bf8c3db6ea5Howard Hinnant//
8a6a062df66fe49704bd074464af30bf8c3db6ea5Howard Hinnant//===----------------------------------------------------------------------===//
9d7cddf651933c246f4b2c4b3de4a4751a9a050dbHoward Hinnant//
104dc5b2198d1aa4ab585a3d4a87ee9626d681f9f7Dan Albert// XFAIL: with_system_cxx_lib=x86_64-apple-darwin11
114dc5b2198d1aa4ab585a3d4a87ee9626d681f9f7Dan Albert// XFAIL: with_system_cxx_lib=x86_64-apple-darwin12
12a6a062df66fe49704bd074464af30bf8c3db6ea5Howard Hinnant
13a6a062df66fe49704bd074464af30bf8c3db6ea5Howard Hinnant// <string>
14a6a062df66fe49704bd074464af30bf8c3db6ea5Howard Hinnant
15a6a062df66fe49704bd074464af30bf8c3db6ea5Howard Hinnant// unsigned long stoul(const string& str, size_t *idx = 0, int base = 10);
16a6a062df66fe49704bd074464af30bf8c3db6ea5Howard Hinnant// unsigned long stoul(const wstring& str, size_t *idx = 0, int base = 10);
17a6a062df66fe49704bd074464af30bf8c3db6ea5Howard Hinnant
18a6a062df66fe49704bd074464af30bf8c3db6ea5Howard Hinnant#include <string>
19a6a062df66fe49704bd074464af30bf8c3db6ea5Howard Hinnant#include <cassert>
20a6a062df66fe49704bd074464af30bf8c3db6ea5Howard Hinnant
21a6a062df66fe49704bd074464af30bf8c3db6ea5Howard Hinnantint main()
22a6a062df66fe49704bd074464af30bf8c3db6ea5Howard Hinnant{
23a6a062df66fe49704bd074464af30bf8c3db6ea5Howard Hinnant    assert(std::stoul("0") == 0);
24a6a062df66fe49704bd074464af30bf8c3db6ea5Howard Hinnant    assert(std::stoul(L"0") == 0);
25a6a062df66fe49704bd074464af30bf8c3db6ea5Howard Hinnant    assert(std::stoul("-0") == 0);
26a6a062df66fe49704bd074464af30bf8c3db6ea5Howard Hinnant    assert(std::stoul(L"-0") == 0);
27a6a062df66fe49704bd074464af30bf8c3db6ea5Howard Hinnant    assert(std::stoul(" 10") == 10);
28a6a062df66fe49704bd074464af30bf8c3db6ea5Howard Hinnant    assert(std::stoul(L" 10") == 10);
29a6a062df66fe49704bd074464af30bf8c3db6ea5Howard Hinnant    size_t idx = 0;
30a6a062df66fe49704bd074464af30bf8c3db6ea5Howard Hinnant    assert(std::stoul("10g", &idx, 16) == 16);
31a6a062df66fe49704bd074464af30bf8c3db6ea5Howard Hinnant    assert(idx == 2);
32a6a062df66fe49704bd074464af30bf8c3db6ea5Howard Hinnant    idx = 0;
33a6a062df66fe49704bd074464af30bf8c3db6ea5Howard Hinnant    assert(std::stoul(L"10g", &idx, 16) == 16);
34a6a062df66fe49704bd074464af30bf8c3db6ea5Howard Hinnant    assert(idx == 2);
35a6a062df66fe49704bd074464af30bf8c3db6ea5Howard Hinnant    idx = 0;
36a6a062df66fe49704bd074464af30bf8c3db6ea5Howard Hinnant    try
37a6a062df66fe49704bd074464af30bf8c3db6ea5Howard Hinnant    {
38a6a062df66fe49704bd074464af30bf8c3db6ea5Howard Hinnant        std::stoul("", &idx);
39a6a062df66fe49704bd074464af30bf8c3db6ea5Howard Hinnant        assert(false);
40a6a062df66fe49704bd074464af30bf8c3db6ea5Howard Hinnant    }
41a6a062df66fe49704bd074464af30bf8c3db6ea5Howard Hinnant    catch (const std::invalid_argument&)
42a6a062df66fe49704bd074464af30bf8c3db6ea5Howard Hinnant    {
43a6a062df66fe49704bd074464af30bf8c3db6ea5Howard Hinnant        assert(idx == 0);
44a6a062df66fe49704bd074464af30bf8c3db6ea5Howard Hinnant    }
45a6a062df66fe49704bd074464af30bf8c3db6ea5Howard Hinnant    try
46a6a062df66fe49704bd074464af30bf8c3db6ea5Howard Hinnant    {
47a6a062df66fe49704bd074464af30bf8c3db6ea5Howard Hinnant        std::stoul(L"", &idx);
48a6a062df66fe49704bd074464af30bf8c3db6ea5Howard Hinnant        assert(false);
49a6a062df66fe49704bd074464af30bf8c3db6ea5Howard Hinnant    }
50a6a062df66fe49704bd074464af30bf8c3db6ea5Howard Hinnant    catch (const std::invalid_argument&)
51a6a062df66fe49704bd074464af30bf8c3db6ea5Howard Hinnant    {
52a6a062df66fe49704bd074464af30bf8c3db6ea5Howard Hinnant        assert(idx == 0);
53a6a062df66fe49704bd074464af30bf8c3db6ea5Howard Hinnant    }
54a6a062df66fe49704bd074464af30bf8c3db6ea5Howard Hinnant    try
55a6a062df66fe49704bd074464af30bf8c3db6ea5Howard Hinnant    {
56a6a062df66fe49704bd074464af30bf8c3db6ea5Howard Hinnant        std::stoul("  - 8", &idx);
57a6a062df66fe49704bd074464af30bf8c3db6ea5Howard Hinnant        assert(false);
58a6a062df66fe49704bd074464af30bf8c3db6ea5Howard Hinnant    }
59a6a062df66fe49704bd074464af30bf8c3db6ea5Howard Hinnant    catch (const std::invalid_argument&)
60a6a062df66fe49704bd074464af30bf8c3db6ea5Howard Hinnant    {
61a6a062df66fe49704bd074464af30bf8c3db6ea5Howard Hinnant        assert(idx == 0);
62a6a062df66fe49704bd074464af30bf8c3db6ea5Howard Hinnant    }
63a6a062df66fe49704bd074464af30bf8c3db6ea5Howard Hinnant    try
64a6a062df66fe49704bd074464af30bf8c3db6ea5Howard Hinnant    {
65a6a062df66fe49704bd074464af30bf8c3db6ea5Howard Hinnant        std::stoul(L"  - 8", &idx);
66a6a062df66fe49704bd074464af30bf8c3db6ea5Howard Hinnant        assert(false);
67a6a062df66fe49704bd074464af30bf8c3db6ea5Howard Hinnant    }
68a6a062df66fe49704bd074464af30bf8c3db6ea5Howard Hinnant    catch (const std::invalid_argument&)
69a6a062df66fe49704bd074464af30bf8c3db6ea5Howard Hinnant    {
70a6a062df66fe49704bd074464af30bf8c3db6ea5Howard Hinnant        assert(idx == 0);
71a6a062df66fe49704bd074464af30bf8c3db6ea5Howard Hinnant    }
72a6a062df66fe49704bd074464af30bf8c3db6ea5Howard Hinnant    try
73a6a062df66fe49704bd074464af30bf8c3db6ea5Howard Hinnant    {
74a6a062df66fe49704bd074464af30bf8c3db6ea5Howard Hinnant        std::stoul("a1", &idx);
75a6a062df66fe49704bd074464af30bf8c3db6ea5Howard Hinnant        assert(false);
76a6a062df66fe49704bd074464af30bf8c3db6ea5Howard Hinnant    }
77a6a062df66fe49704bd074464af30bf8c3db6ea5Howard Hinnant    catch (const std::invalid_argument&)
78a6a062df66fe49704bd074464af30bf8c3db6ea5Howard Hinnant    {
79a6a062df66fe49704bd074464af30bf8c3db6ea5Howard Hinnant        assert(idx == 0);
80a6a062df66fe49704bd074464af30bf8c3db6ea5Howard Hinnant    }
81a6a062df66fe49704bd074464af30bf8c3db6ea5Howard Hinnant    try
82a6a062df66fe49704bd074464af30bf8c3db6ea5Howard Hinnant    {
83a6a062df66fe49704bd074464af30bf8c3db6ea5Howard Hinnant        std::stoul(L"a1", &idx);
84a6a062df66fe49704bd074464af30bf8c3db6ea5Howard Hinnant        assert(false);
85a6a062df66fe49704bd074464af30bf8c3db6ea5Howard Hinnant    }
86a6a062df66fe49704bd074464af30bf8c3db6ea5Howard Hinnant    catch (const std::invalid_argument&)
87a6a062df66fe49704bd074464af30bf8c3db6ea5Howard Hinnant    {
88a6a062df66fe49704bd074464af30bf8c3db6ea5Howard Hinnant        assert(idx == 0);
89a6a062df66fe49704bd074464af30bf8c3db6ea5Howard Hinnant    }
90bf6eda0b1e50f1194ed07df89840e4e9c5f05fddMarshall Clow//  LWG issue #2009
918634fc5494641850c89eab7a1f2357a55d694c0cMarshall Clow    try
928634fc5494641850c89eab7a1f2357a55d694c0cMarshall Clow    {
938634fc5494641850c89eab7a1f2357a55d694c0cMarshall Clow        std::stoul("9999999999999999999999999999999999999999999999999", &idx);
948634fc5494641850c89eab7a1f2357a55d694c0cMarshall Clow        assert(false);
958634fc5494641850c89eab7a1f2357a55d694c0cMarshall Clow    }
968634fc5494641850c89eab7a1f2357a55d694c0cMarshall Clow    catch (const std::out_of_range&)
978634fc5494641850c89eab7a1f2357a55d694c0cMarshall Clow    {
988634fc5494641850c89eab7a1f2357a55d694c0cMarshall Clow        assert(idx == 0);
998634fc5494641850c89eab7a1f2357a55d694c0cMarshall Clow    }
1008634fc5494641850c89eab7a1f2357a55d694c0cMarshall Clow    try
1018634fc5494641850c89eab7a1f2357a55d694c0cMarshall Clow    {
1028634fc5494641850c89eab7a1f2357a55d694c0cMarshall Clow        std::stoul(L"9999999999999999999999999999999999999999999999999", &idx);
1038634fc5494641850c89eab7a1f2357a55d694c0cMarshall Clow        assert(false);
1048634fc5494641850c89eab7a1f2357a55d694c0cMarshall Clow    }
1058634fc5494641850c89eab7a1f2357a55d694c0cMarshall Clow    catch (const std::out_of_range&)
1068634fc5494641850c89eab7a1f2357a55d694c0cMarshall Clow    {
1078634fc5494641850c89eab7a1f2357a55d694c0cMarshall Clow        assert(idx == 0);
1088634fc5494641850c89eab7a1f2357a55d694c0cMarshall Clow    }
109a6a062df66fe49704bd074464af30bf8c3db6ea5Howard Hinnant}
110