Howard Hinnant | cbbf633 | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Howard Hinnant | 412dbeb | 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 | cbbf633 | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
Howard Hinnant | 56c917c | 2013-08-22 00:04:22 +0000 | [diff] [blame] | 9 | // |
Mehdi Amini | e9c66ad | 2017-05-04 17:08:54 +0000 | [diff] [blame] | 10 | // PR14919 was fixed in r172447, out_of_range wasn't thrown before. |
| 11 | // XFAIL: with_system_cxx_lib=macosx10.7 |
| 12 | // XFAIL: with_system_cxx_lib=macosx10.8 |
Howard Hinnant | cbbf633 | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 13 | |
| 14 | // <string> |
| 15 | |
| 16 | // unsigned long long stoull(const string& str, size_t *idx = 0, int base = 10); |
| 17 | // unsigned long long stoull(const wstring& str, size_t *idx = 0, int base = 10); |
| 18 | |
| 19 | #include <string> |
| 20 | #include <cassert> |
Billy Robert O'Neal III | ed2f9a6 | 2018-08-08 00:40:32 +0000 | [diff] [blame] | 21 | #include <stdexcept> |
Howard Hinnant | cbbf633 | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 22 | |
Roger Ferrer Ibanez | 84c152a | 2016-11-14 10:44:26 +0000 | [diff] [blame] | 23 | #include "test_macros.h" |
| 24 | |
Howard Hinnant | cbbf633 | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 25 | int main() |
| 26 | { |
| 27 | assert(std::stoull("0") == 0); |
| 28 | assert(std::stoull(L"0") == 0); |
| 29 | assert(std::stoull("-0") == 0); |
| 30 | assert(std::stoull(L"-0") == 0); |
| 31 | assert(std::stoull(" 10") == 10); |
| 32 | assert(std::stoull(L" 10") == 10); |
| 33 | size_t idx = 0; |
| 34 | assert(std::stoull("10g", &idx, 16) == 16); |
| 35 | assert(idx == 2); |
| 36 | idx = 0; |
| 37 | assert(std::stoull(L"10g", &idx, 16) == 16); |
| 38 | assert(idx == 2); |
Roger Ferrer Ibanez | 84c152a | 2016-11-14 10:44:26 +0000 | [diff] [blame] | 39 | #ifndef TEST_HAS_NO_EXCEPTIONS |
Howard Hinnant | cbbf633 | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 40 | idx = 0; |
| 41 | try |
| 42 | { |
| 43 | std::stoull("", &idx); |
| 44 | assert(false); |
| 45 | } |
| 46 | catch (const std::invalid_argument&) |
| 47 | { |
| 48 | assert(idx == 0); |
| 49 | } |
| 50 | idx = 0; |
| 51 | try |
| 52 | { |
| 53 | std::stoull(L"", &idx); |
| 54 | assert(false); |
| 55 | } |
| 56 | catch (const std::invalid_argument&) |
| 57 | { |
| 58 | assert(idx == 0); |
| 59 | } |
| 60 | try |
| 61 | { |
| 62 | std::stoull(" - 8", &idx); |
| 63 | assert(false); |
| 64 | } |
| 65 | catch (const std::invalid_argument&) |
| 66 | { |
| 67 | assert(idx == 0); |
| 68 | } |
| 69 | try |
| 70 | { |
| 71 | std::stoull(L" - 8", &idx); |
| 72 | assert(false); |
| 73 | } |
| 74 | catch (const std::invalid_argument&) |
| 75 | { |
| 76 | assert(idx == 0); |
| 77 | } |
| 78 | try |
| 79 | { |
| 80 | std::stoull("a1", &idx); |
| 81 | assert(false); |
| 82 | } |
| 83 | catch (const std::invalid_argument&) |
| 84 | { |
| 85 | assert(idx == 0); |
| 86 | } |
| 87 | try |
| 88 | { |
| 89 | std::stoull(L"a1", &idx); |
| 90 | assert(false); |
| 91 | } |
| 92 | catch (const std::invalid_argument&) |
| 93 | { |
| 94 | assert(idx == 0); |
| 95 | } |
Marshall Clow | e4fa0de | 2013-08-13 22:22:40 +0000 | [diff] [blame] | 96 | // LWG issue #2009 |
Marshall Clow | 914993d | 2013-08-13 15:52:51 +0000 | [diff] [blame] | 97 | try |
| 98 | { |
| 99 | std::stoull("9999999999999999999999999999999999999999999999999", &idx); |
| 100 | assert(false); |
| 101 | } |
| 102 | catch (const std::out_of_range&) |
| 103 | { |
| 104 | assert(idx == 0); |
| 105 | } |
| 106 | try |
| 107 | { |
| 108 | std::stoull(L"9999999999999999999999999999999999999999999999999", &idx); |
| 109 | assert(false); |
| 110 | } |
| 111 | catch (const std::out_of_range&) |
| 112 | { |
| 113 | assert(idx == 0); |
| 114 | } |
Roger Ferrer Ibanez | 84c152a | 2016-11-14 10:44:26 +0000 | [diff] [blame] | 115 | #endif |
Howard Hinnant | cbbf633 | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 116 | } |