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"
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);
29 assert(std::stoul("10g", &idx
, 16) == 16);
32 assert(std::stoul(L
"10g", &idx
, 16) == 16);
34 #ifndef TEST_HAS_NO_EXCEPTIONS
41 catch (const std::invalid_argument
&)
47 std::stoul(L
"", &idx
);
50 catch (const std::invalid_argument
&)
56 std::stoul(" - 8", &idx
);
59 catch (const std::invalid_argument
&)
65 std::stoul(L
" - 8", &idx
);
68 catch (const std::invalid_argument
&)
74 std::stoul("a1", &idx
);
77 catch (const std::invalid_argument
&)
83 std::stoul(L
"a1", &idx
);
86 catch (const std::invalid_argument
&)
92 // LWG#2009 and PR14919
93 std::stoul("9999999999999999999999999999999999999999999999999", &idx
);
96 catch (const std::out_of_range
&)
102 // LWG#2009 and PR14919
103 std::stoul(L
"9999999999999999999999999999999999999999999999999", &idx
);
106 catch (const std::out_of_range
&)