blob: 9dbd952434a9bd611e8b8c0baa00dff0df699b67 [file] [log] [blame]
Howard Hinnantcbbf6332010-06-02 18:20:39 +00001//===----------------------------------------------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Howard Hinnant412dbeb2010-11-16 22:09:02 +00005// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantcbbf6332010-06-02 18:20:39 +00007//
8//===----------------------------------------------------------------------===//
Howard Hinnant56c917c2013-08-22 00:04:22 +00009//
Asiri Rathnayakef520c142015-11-10 11:41:22 +000010// XFAIL: libcpp-no-exceptions
Jonathan Roelofseb7b5e72015-01-14 23:38:12 +000011// XFAIL: with_system_cxx_lib=x86_64-apple-darwin11
12// XFAIL: with_system_cxx_lib=x86_64-apple-darwin12
Howard Hinnantcbbf6332010-06-02 18:20:39 +000013
14// <string>
15
16// unsigned long stoul(const string& str, size_t *idx = 0, int base = 10);
17// unsigned long stoul(const wstring& str, size_t *idx = 0, int base = 10);
18
19#include <string>
20#include <cassert>
21
22int main()
23{
24 assert(std::stoul("0") == 0);
25 assert(std::stoul(L"0") == 0);
26 assert(std::stoul("-0") == 0);
27 assert(std::stoul(L"-0") == 0);
28 assert(std::stoul(" 10") == 10);
29 assert(std::stoul(L" 10") == 10);
30 size_t idx = 0;
31 assert(std::stoul("10g", &idx, 16) == 16);
32 assert(idx == 2);
33 idx = 0;
34 assert(std::stoul(L"10g", &idx, 16) == 16);
35 assert(idx == 2);
36 idx = 0;
37 try
38 {
39 std::stoul("", &idx);
40 assert(false);
41 }
42 catch (const std::invalid_argument&)
43 {
44 assert(idx == 0);
45 }
46 try
47 {
48 std::stoul(L"", &idx);
49 assert(false);
50 }
51 catch (const std::invalid_argument&)
52 {
53 assert(idx == 0);
54 }
55 try
56 {
57 std::stoul(" - 8", &idx);
58 assert(false);
59 }
60 catch (const std::invalid_argument&)
61 {
62 assert(idx == 0);
63 }
64 try
65 {
66 std::stoul(L" - 8", &idx);
67 assert(false);
68 }
69 catch (const std::invalid_argument&)
70 {
71 assert(idx == 0);
72 }
73 try
74 {
75 std::stoul("a1", &idx);
76 assert(false);
77 }
78 catch (const std::invalid_argument&)
79 {
80 assert(idx == 0);
81 }
82 try
83 {
84 std::stoul(L"a1", &idx);
85 assert(false);
86 }
87 catch (const std::invalid_argument&)
88 {
89 assert(idx == 0);
90 }
Marshall Clowe4fa0de2013-08-13 22:22:40 +000091// LWG issue #2009
Marshall Clow914993d2013-08-13 15:52:51 +000092 try
93 {
94 std::stoul("9999999999999999999999999999999999999999999999999", &idx);
95 assert(false);
96 }
97 catch (const std::out_of_range&)
98 {
99 assert(idx == 0);
100 }
101 try
102 {
103 std::stoul(L"9999999999999999999999999999999999999999999999999", &idx);
104 assert(false);
105 }
106 catch (const std::out_of_range&)
107 {
108 assert(idx == 0);
109 }
Howard Hinnantcbbf6332010-06-02 18:20:39 +0000110}