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 // long stol(const string& str, size_t *idx = 0, int base = 10);
12 // long stol(const wstring& str, size_t *idx = 0, int base = 10);
19 #include "test_macros.h"
21 int main(int, char**) {
22 assert(std::stol("0") == 0);
23 assert(std::stol("-0") == 0);
24 assert(std::stol("-10") == -10);
25 assert(std::stol(" 10") == 10);
28 assert(std::stol("10g", &idx
, 16) == 16);
31 #ifndef TEST_HAS_NO_EXCEPTIONS
35 (void)std::stol("", &idx
);
37 } catch (const std::invalid_argument
&) {
44 (void)std::stol(" - 8", &idx
);
46 } catch (const std::invalid_argument
&) {
53 (void)std::stol("a1", &idx
);
55 } catch (const std::invalid_argument
&) {
62 // LWG#2009 and PR14919
63 (void)std::stol("9999999999999999999999999999999999999999999999999", &idx
);
65 } catch (const std::out_of_range
&) {
69 #endif // TEST_HAS_NO_EXCEPTIONS
71 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
72 assert(std::stol(L
"0") == 0);
73 assert(std::stol(L
"-0") == 0);
74 assert(std::stol(L
"-10") == -10);
75 assert(std::stol(L
" 10") == 10);
78 assert(std::stol(L
"10g", &idx
, 16) == 16);
81 # ifndef TEST_HAS_NO_EXCEPTIONS
85 (void)std::stol(L
"", &idx
);
87 } catch (const std::invalid_argument
&) {
94 (void)std::stol(L
" - 8", &idx
);
96 } catch (const std::invalid_argument
&) {
103 (void)std::stol(L
"a1", &idx
);
105 } catch (const std::invalid_argument
&) {
112 // LWG#2009 and PR14919
113 (void)std::stol(L
"9999999999999999999999999999999999999999999999999", &idx
);
115 } catch (const std::out_of_range
&) {
119 # endif // TEST_HAS_NO_EXCEPTIONS
120 #endif // TEST_HAS_NO_WIDE_CHARACTERS