[TableGen][SystemZ] Correctly check the range of a leaf immediate (#119931)
[llvm-project.git] / libcxx / test / std / strings / string.conversions / stoul.pass.cpp
blobedc4a795baa21813999ab9b00afc7a91a0535e74
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**) {
21 assert(std::stoul("0") == 0);
22 assert(std::stoul("-0") == 0);
23 assert(std::stoul(" 10") == 10);
25 std::size_t idx = 0;
26 assert(std::stoul("10g", &idx, 16) == 16);
27 assert(idx == 2);
29 #ifndef TEST_HAS_NO_EXCEPTIONS
31 std::size_t idx = 0;
32 try {
33 (void)std::stoul("", &idx);
34 assert(false);
35 } catch (const std::invalid_argument&) {
36 assert(idx == 0);
40 std::size_t idx = 0;
41 try {
42 (void)std::stoul(" - 8", &idx);
43 assert(false);
44 } catch (const std::invalid_argument&) {
45 assert(idx == 0);
49 std::size_t idx = 0;
50 try {
51 (void)std::stoul("a1", &idx);
52 assert(false);
53 } catch (const std::invalid_argument&) {
54 assert(idx == 0);
58 std::size_t idx = 0;
59 try {
60 // LWG#2009 and PR14919
61 (void)std::stoul("9999999999999999999999999999999999999999999999999", &idx);
62 assert(false);
63 } catch (const std::out_of_range&) {
64 assert(idx == 0);
67 #endif // TEST_HAS_NO_EXCEPTIONS
69 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
70 assert(std::stoul(L"0") == 0);
71 assert(std::stoul(L"-0") == 0);
72 assert(std::stoul(L" 10") == 10);
74 std::size_t idx = 0;
75 assert(std::stoul(L"10g", &idx, 16) == 16);
76 assert(idx == 2);
78 # ifndef TEST_HAS_NO_EXCEPTIONS
80 std::size_t idx = 0;
81 try {
82 (void)std::stoul(L"", &idx);
83 assert(false);
84 } catch (const std::invalid_argument&) {
85 assert(idx == 0);
89 std::size_t idx = 0;
90 try {
91 (void)std::stoul(L" - 8", &idx);
92 assert(false);
93 } catch (const std::invalid_argument&) {
94 assert(idx == 0);
98 std::size_t idx = 0;
99 try {
100 (void)std::stoul(L"a1", &idx);
101 assert(false);
102 } catch (const std::invalid_argument&) {
103 assert(idx == 0);
107 std::size_t idx = 0;
108 try {
109 // LWG#2009 and PR14919
110 (void)std::stoul(L"9999999999999999999999999999999999999999999999999", &idx);
111 assert(false);
112 } catch (const std::out_of_range&) {
113 assert(idx == 0);
116 # endif // TEST_HAS_NO_EXCEPTIONS
117 #endif // TEST_HAS_NO_WIDE_CHARACTERS
119 return 0;