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