[PowerPC][NFC] Cleanup PPCCTRLoopsVerify pass
[llvm-project.git] / libcxx / test / std / strings / string.conversions / stoul.pass.cpp
blobc620925d85d49c518ebc8e477c271f66a3a7f9f9
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 // <string>
11 // unsigned long stoul(const string& str, size_t *idx = 0, int base = 10);
12 // unsigned long stoul(const wstring& str, size_t *idx = 0, int base = 10);
14 #include <string>
15 #include <cassert>
16 #include <stdexcept>
18 #include "test_macros.h"
20 int main(int, char**)
22 assert(std::stoul("0") == 0);
23 assert(std::stoul(L"0") == 0);
24 assert(std::stoul("-0") == 0);
25 assert(std::stoul(L"-0") == 0);
26 assert(std::stoul(" 10") == 10);
27 assert(std::stoul(L" 10") == 10);
28 size_t idx = 0;
29 assert(std::stoul("10g", &idx, 16) == 16);
30 assert(idx == 2);
31 idx = 0;
32 assert(std::stoul(L"10g", &idx, 16) == 16);
33 assert(idx == 2);
34 #ifndef TEST_HAS_NO_EXCEPTIONS
35 idx = 0;
36 try
38 std::stoul("", &idx);
39 assert(false);
41 catch (const std::invalid_argument&)
43 assert(idx == 0);
45 try
47 std::stoul(L"", &idx);
48 assert(false);
50 catch (const std::invalid_argument&)
52 assert(idx == 0);
54 try
56 std::stoul(" - 8", &idx);
57 assert(false);
59 catch (const std::invalid_argument&)
61 assert(idx == 0);
63 try
65 std::stoul(L" - 8", &idx);
66 assert(false);
68 catch (const std::invalid_argument&)
70 assert(idx == 0);
72 try
74 std::stoul("a1", &idx);
75 assert(false);
77 catch (const std::invalid_argument&)
79 assert(idx == 0);
81 try
83 std::stoul(L"a1", &idx);
84 assert(false);
86 catch (const std::invalid_argument&)
88 assert(idx == 0);
90 try
92 // LWG#2009 and PR14919
93 std::stoul("9999999999999999999999999999999999999999999999999", &idx);
94 assert(false);
96 catch (const std::out_of_range&)
98 assert(idx == 0);
102 // LWG#2009 and PR14919
103 std::stoul(L"9999999999999999999999999999999999999999999999999", &idx);
104 assert(false);
106 catch (const std::out_of_range&)
108 assert(idx == 0);
110 #endif
112 return 0;