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 | //===----------------------------------------------------------------------===// |
Howard Hinnant | d7cddf6 | 2013-08-22 00:04:22 +0000 | [diff] [blame] | 9 | // |
Jonathan Roelofs | 3345961 | 2015-01-14 23:38:12 +0000 | [diff] [blame] | 10 | // XFAIL: with_system_cxx_lib=x86_64-apple-darwin11 |
| 11 | // XFAIL: with_system_cxx_lib=x86_64-apple-darwin12 |
Howard Hinnant | a6a062d | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 12 | |
| 13 | // <string> |
| 14 | |
| 15 | // long stol(const string& str, size_t *idx = 0, int base = 10); |
| 16 | // long stol(const wstring& str, size_t *idx = 0, int base = 10); |
| 17 | |
| 18 | #include <string> |
| 19 | #include <cassert> |
| 20 | |
| 21 | int main() |
| 22 | { |
| 23 | assert(std::stol("0") == 0); |
| 24 | assert(std::stol(L"0") == 0); |
| 25 | assert(std::stol("-0") == 0); |
| 26 | assert(std::stol(L"-0") == 0); |
| 27 | assert(std::stol("-10") == -10); |
| 28 | assert(std::stol(L"-10") == -10); |
| 29 | assert(std::stol(" 10") == 10); |
| 30 | assert(std::stol(L" 10") == 10); |
| 31 | size_t idx = 0; |
| 32 | assert(std::stol("10g", &idx, 16) == 16); |
| 33 | assert(idx == 2); |
| 34 | idx = 0; |
| 35 | assert(std::stol(L"10g", &idx, 16) == 16); |
| 36 | assert(idx == 2); |
| 37 | idx = 0; |
| 38 | try |
| 39 | { |
| 40 | std::stol("", &idx); |
| 41 | assert(false); |
| 42 | } |
| 43 | catch (const std::invalid_argument&) |
| 44 | { |
| 45 | assert(idx == 0); |
| 46 | } |
| 47 | try |
| 48 | { |
| 49 | std::stol(L"", &idx); |
| 50 | assert(false); |
| 51 | } |
| 52 | catch (const std::invalid_argument&) |
| 53 | { |
| 54 | assert(idx == 0); |
| 55 | } |
| 56 | try |
| 57 | { |
| 58 | std::stol(" - 8", &idx); |
| 59 | assert(false); |
| 60 | } |
| 61 | catch (const std::invalid_argument&) |
| 62 | { |
| 63 | assert(idx == 0); |
| 64 | } |
| 65 | try |
| 66 | { |
| 67 | std::stol(L" - 8", &idx); |
| 68 | assert(false); |
| 69 | } |
| 70 | catch (const std::invalid_argument&) |
| 71 | { |
| 72 | assert(idx == 0); |
| 73 | } |
| 74 | try |
| 75 | { |
| 76 | std::stol("a1", &idx); |
| 77 | assert(false); |
| 78 | } |
| 79 | catch (const std::invalid_argument&) |
| 80 | { |
| 81 | assert(idx == 0); |
| 82 | } |
| 83 | try |
| 84 | { |
| 85 | std::stol(L"a1", &idx); |
| 86 | assert(false); |
| 87 | } |
| 88 | catch (const std::invalid_argument&) |
| 89 | { |
| 90 | assert(idx == 0); |
| 91 | } |
Marshall Clow | bf6eda0 | 2013-08-13 22:22:40 +0000 | [diff] [blame] | 92 | // LWG issue #2009 |
Marshall Clow | 8634fc5 | 2013-08-13 15:52:51 +0000 | [diff] [blame] | 93 | try |
| 94 | { |
| 95 | std::stol("9999999999999999999999999999999999999999999999999", &idx); |
| 96 | assert(false); |
| 97 | } |
| 98 | catch (const std::out_of_range&) |
| 99 | { |
| 100 | assert(idx == 0); |
| 101 | } |
| 102 | try |
| 103 | { |
| 104 | std::stol(L"9999999999999999999999999999999999999999999999999", &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 | } |