1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
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);
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);
26 assert(std::stoul("10g", &idx
, 16) == 16);
29 #ifndef TEST_HAS_NO_EXCEPTIONS
33 (void)std::stoul("", &idx
);
35 } catch (const std::invalid_argument
&) {
42 (void)std::stoul(" - 8", &idx
);
44 } catch (const std::invalid_argument
&) {
51 (void)std::stoul("a1", &idx
);
53 } catch (const std::invalid_argument
&) {
60 // LWG#2009 and PR14919
61 (void)std::stoul("9999999999999999999999999999999999999999999999999", &idx
);
63 } catch (const std::out_of_range
&) {
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);
75 assert(std::stoul(L
"10g", &idx
, 16) == 16);
78 # ifndef TEST_HAS_NO_EXCEPTIONS
82 (void)std::stoul(L
"", &idx
);
84 } catch (const std::invalid_argument
&) {
91 (void)std::stoul(L
" - 8", &idx
);
93 } catch (const std::invalid_argument
&) {
100 (void)std::stoul(L
"a1", &idx
);
102 } catch (const std::invalid_argument
&) {
109 // LWG#2009 and PR14919
110 (void)std::stoul(L
"9999999999999999999999999999999999999999999999999", &idx
);
112 } catch (const std::out_of_range
&) {
116 # endif // TEST_HAS_NO_EXCEPTIONS
117 #endif // TEST_HAS_NO_WIDE_CHARACTERS