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 // int stoi(const string& str, size_t *idx = 0, int base = 10);
12 // int stoi(const wstring& str, size_t *idx = 0, int base = 10);
18 #include "test_macros.h"
20 int main(int, char**) {
21 assert(std::stoi("0") == 0);
22 assert(std::stoi("-0") == 0);
23 assert(std::stoi("-10") == -10);
24 assert(std::stoi(" 10") == 10);
27 assert(std::stoi("10g", &idx
, 16) == 16);
30 #ifndef TEST_HAS_NO_EXCEPTIONS
31 if (std::numeric_limits
<long>::max() > std::numeric_limits
<int>::max()) {
34 (void)std::stoi("0x100000000", &idx
, 16);
36 } catch (const std::out_of_range
&) {
42 (void)std::stoi("", &idx
);
44 } catch (const std::invalid_argument
&) {
51 (void)std::stoi(" - 8", &idx
);
53 } catch (const std::invalid_argument
&) {
60 (void)std::stoi("a1", &idx
);
62 } catch (const std::invalid_argument
&) {
66 #endif // TEST_HAS_NO_EXCEPTIONS
68 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
69 assert(std::stoi(L
"0") == 0);
70 assert(std::stoi(L
"-0") == 0);
71 assert(std::stoi(L
"-10") == -10);
72 assert(std::stoi(L
" 10") == 10);
75 assert(std::stoi(L
"10g", &idx
, 16) == 16);
78 # ifndef TEST_HAS_NO_EXCEPTIONS
79 if (std::numeric_limits
<long>::max() > std::numeric_limits
<int>::max()) {
82 (void)std::stoi(L
"0x100000000", &idx
, 16);
84 } catch (const std::out_of_range
&) {
90 (void)std::stoi(L
"", &idx
);
92 } catch (const std::invalid_argument
&) {
99 (void)std::stoi(L
" - 8", &idx
);
101 } catch (const std::invalid_argument
&) {
108 (void)std::stoi(L
"a1", &idx
);
110 } catch (const std::invalid_argument
&) {
114 # endif // TEST_HAS_NO_EXCEPTIONS
115 #endif // TEST_HAS_NO_WIDE_CHARACTERS