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 // 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> 21 22 #include "test_macros.h" 23 24 int main() 25 { 26 assert(std::stoull("0") == 0); 27 assert(std::stoull(L"0") == 0); 28 assert(std::stoull("-0") == 0); 29 assert(std::stoull(L"-0") == 0); 30 assert(std::stoull(" 10") == 10); 31 assert(std::stoull(L" 10") == 10); 32 size_t idx = 0; 33 assert(std::stoull("10g", &idx, 16) == 16); 34 assert(idx == 2); 35 idx = 0; 36 assert(std::stoull(L"10g", &idx, 16) == 16); 37 assert(idx == 2); 38 #ifndef TEST_HAS_NO_EXCEPTIONS 39 idx = 0; 40 try 41 { 42 std::stoull("", &idx); 43 assert(false); 44 } 45 catch (const std::invalid_argument&) 46 { 47 assert(idx == 0); 48 } 49 idx = 0; 50 try 51 { 52 std::stoull(L"", &idx); 53 assert(false); 54 } 55 catch (const std::invalid_argument&) 56 { 57 assert(idx == 0); 58 } 59 try 60 { 61 std::stoull(" - 8", &idx); 62 assert(false); 63 } 64 catch (const std::invalid_argument&) 65 { 66 assert(idx == 0); 67 } 68 try 69 { 70 std::stoull(L" - 8", &idx); 71 assert(false); 72 } 73 catch (const std::invalid_argument&) 74 { 75 assert(idx == 0); 76 } 77 try 78 { 79 std::stoull("a1", &idx); 80 assert(false); 81 } 82 catch (const std::invalid_argument&) 83 { 84 assert(idx == 0); 85 } 86 try 87 { 88 std::stoull(L"a1", &idx); 89 assert(false); 90 } 91 catch (const std::invalid_argument&) 92 { 93 assert(idx == 0); 94 } 95 // LWG issue #2009 96 try 97 { 98 std::stoull("9999999999999999999999999999999999999999999999999", &idx); 99 assert(false); 100 } 101 catch (const std::out_of_range&) 102 { 103 assert(idx == 0); 104 } 105 try 106 { 107 std::stoull(L"9999999999999999999999999999999999999999999999999", &idx); 108 assert(false); 109 } 110 catch (const std::out_of_range&) 111 { 112 assert(idx == 0); 113 } 114 #endif 115 } 116