Howard Hinnant | a6a062d | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Howard Hinnant | b64f8b0 | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 5 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | // Source Licenses. See LICENSE.TXT for details. |
Howard Hinnant | a6a062d | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
Daniel Dunbar | c8e1889 | 2013-02-05 22:10:27 +0000 | [diff] [blame] | 9 | // |
Asiri Rathnayake | cc2e93c | 2015-11-10 11:41:22 +0000 | [diff] [blame] | 10 | // XFAIL: libcpp-no-exceptions |
Jonathan Roelofs | 3345961 | 2015-01-14 23:38:12 +0000 | [diff] [blame] | 11 | // XFAIL: with_system_cxx_lib=x86_64-apple-darwin11 |
| 12 | // XFAIL: with_system_cxx_lib=x86_64-apple-darwin12 |
Howard Hinnant | a6a062d | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 13 | |
| 14 | // <string> |
| 15 | |
| 16 | // long long stoll(const string& str, size_t *idx = 0, int base = 10); |
| 17 | // long long stoll(const wstring& str, size_t *idx = 0, int base = 10); |
| 18 | |
| 19 | #include <string> |
| 20 | #include <cassert> |
| 21 | |
| 22 | int main() |
| 23 | { |
| 24 | assert(std::stoll("0") == 0); |
| 25 | assert(std::stoll(L"0") == 0); |
| 26 | assert(std::stoll("-0") == 0); |
| 27 | assert(std::stoll(L"-0") == 0); |
| 28 | assert(std::stoll("-10") == -10); |
| 29 | assert(std::stoll(L"-10") == -10); |
| 30 | assert(std::stoll(" 10") == 10); |
| 31 | assert(std::stoll(L" 10") == 10); |
| 32 | size_t idx = 0; |
| 33 | assert(std::stoll("10g", &idx, 16) == 16); |
| 34 | assert(idx == 2); |
| 35 | idx = 0; |
| 36 | assert(std::stoll(L"10g", &idx, 16) == 16); |
| 37 | assert(idx == 2); |
| 38 | idx = 0; |
| 39 | try |
| 40 | { |
| 41 | std::stoll("", &idx); |
| 42 | assert(false); |
| 43 | } |
| 44 | catch (const std::invalid_argument&) |
| 45 | { |
| 46 | assert(idx == 0); |
| 47 | } |
| 48 | try |
| 49 | { |
| 50 | std::stoll(L"", &idx); |
| 51 | assert(false); |
| 52 | } |
| 53 | catch (const std::invalid_argument&) |
| 54 | { |
| 55 | assert(idx == 0); |
| 56 | } |
| 57 | try |
| 58 | { |
| 59 | std::stoll(" - 8", &idx); |
| 60 | assert(false); |
| 61 | } |
| 62 | catch (const std::invalid_argument&) |
| 63 | { |
| 64 | assert(idx == 0); |
| 65 | } |
| 66 | try |
| 67 | { |
| 68 | std::stoll(L" - 8", &idx); |
| 69 | assert(false); |
| 70 | } |
| 71 | catch (const std::invalid_argument&) |
| 72 | { |
| 73 | assert(idx == 0); |
| 74 | } |
| 75 | try |
| 76 | { |
| 77 | std::stoll("a1", &idx); |
| 78 | assert(false); |
| 79 | } |
| 80 | catch (const std::invalid_argument&) |
| 81 | { |
| 82 | assert(idx == 0); |
| 83 | } |
| 84 | try |
| 85 | { |
| 86 | std::stoll(L"a1", &idx); |
| 87 | assert(false); |
| 88 | } |
| 89 | catch (const std::invalid_argument&) |
| 90 | { |
| 91 | assert(idx == 0); |
| 92 | } |
Howard Hinnant | 3e3ae9e | 2013-01-14 18:59:43 +0000 | [diff] [blame] | 93 | try |
| 94 | { |
| 95 | std::stoll("99999999999999999999999999", &idx); |
| 96 | assert(false); |
| 97 | } |
| 98 | catch (const std::out_of_range&) |
| 99 | { |
| 100 | assert(idx == 0); |
| 101 | } |
Marshall Clow | 8634fc5 | 2013-08-13 15:52:51 +0000 | [diff] [blame] | 102 | try |
| 103 | { |
| 104 | std::stoll(L"99999999999999999999999999", &idx); |
| 105 | assert(false); |
| 106 | } |
| 107 | catch (const std::out_of_range&) |
| 108 | { |
| 109 | assert(idx == 0); |
| 110 | } |
Howard Hinnant | a6a062d | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 111 | } |