1 //===----------------------------------------------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is dual licensed under the MIT and the University of Illinois Open 6 // Source Licenses. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 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 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 #include <stdexcept> 22 23 #include "test_macros.h" 24 25 int main() 26 { 27 assert(std::stoll("0") == 0); 28 assert(std::stoll(L"0") == 0); 29 assert(std::stoll("-0") == 0); 30 assert(std::stoll(L"-0") == 0); 31 assert(std::stoll("-10") == -10); 32 assert(std::stoll(L"-10") == -10); 33 assert(std::stoll(" 10") == 10); 34 assert(std::stoll(L" 10") == 10); 35 size_t idx = 0; 36 assert(std::stoll("10g", &idx, 16) == 16); 37 assert(idx == 2); 38 idx = 0; 39 assert(std::stoll(L"10g", &idx, 16) == 16); 40 assert(idx == 2); 41 #ifndef TEST_HAS_NO_EXCEPTIONS 42 idx = 0; 43 try 44 { 45 std::stoll("", &idx); 46 assert(false); 47 } 48 catch (const std::invalid_argument&) 49 { 50 assert(idx == 0); 51 } 52 try 53 { 54 std::stoll(L"", &idx); 55 assert(false); 56 } 57 catch (const std::invalid_argument&) 58 { 59 assert(idx == 0); 60 } 61 try 62 { 63 std::stoll(" - 8", &idx); 64 assert(false); 65 } 66 catch (const std::invalid_argument&) 67 { 68 assert(idx == 0); 69 } 70 try 71 { 72 std::stoll(L" - 8", &idx); 73 assert(false); 74 } 75 catch (const std::invalid_argument&) 76 { 77 assert(idx == 0); 78 } 79 try 80 { 81 std::stoll("a1", &idx); 82 assert(false); 83 } 84 catch (const std::invalid_argument&) 85 { 86 assert(idx == 0); 87 } 88 try 89 { 90 std::stoll(L"a1", &idx); 91 assert(false); 92 } 93 catch (const std::invalid_argument&) 94 { 95 assert(idx == 0); 96 } 97 try 98 { 99 std::stoll("99999999999999999999999999", &idx); 100 assert(false); 101 } 102 catch (const std::out_of_range&) 103 { 104 assert(idx == 0); 105 } 106 try 107 { 108 std::stoll(L"99999999999999999999999999", &idx); 109 assert(false); 110 } 111 catch (const std::out_of_range&) 112 { 113 assert(idx == 0); 114 } 115 #endif 116 } 117