blob: c0667edb385eb0ad303c789443330ea2feceace3 [file] [log] [blame]
Howard Hinnanta6a062d2010-06-02 18:20:39 +00001//===----------------------------------------------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00005// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
Howard Hinnanta6a062d2010-06-02 18:20:39 +00007//
8//===----------------------------------------------------------------------===//
Howard Hinnantd7cddf62013-08-22 00:04:22 +00009//
Jonathan Roelofs33459612015-01-14 23:38:12 +000010// XFAIL: with_system_cxx_lib=x86_64-apple-darwin11
11// XFAIL: with_system_cxx_lib=x86_64-apple-darwin12
Howard Hinnanta6a062d2010-06-02 18:20:39 +000012
13// <string>
14
15// unsigned long long stoull(const string& str, size_t *idx = 0, int base = 10);
16// unsigned long long stoull(const wstring& str, size_t *idx = 0, int base = 10);
17
18#include <string>
19#include <cassert>
20
21int main()
22{
23 assert(std::stoull("0") == 0);
24 assert(std::stoull(L"0") == 0);
25 assert(std::stoull("-0") == 0);
26 assert(std::stoull(L"-0") == 0);
27 assert(std::stoull(" 10") == 10);
28 assert(std::stoull(L" 10") == 10);
29 size_t idx = 0;
30 assert(std::stoull("10g", &idx, 16) == 16);
31 assert(idx == 2);
32 idx = 0;
33 assert(std::stoull(L"10g", &idx, 16) == 16);
34 assert(idx == 2);
35 idx = 0;
36 try
37 {
38 std::stoull("", &idx);
39 assert(false);
40 }
41 catch (const std::invalid_argument&)
42 {
43 assert(idx == 0);
44 }
45 idx = 0;
46 try
47 {
48 std::stoull(L"", &idx);
49 assert(false);
50 }
51 catch (const std::invalid_argument&)
52 {
53 assert(idx == 0);
54 }
55 try
56 {
57 std::stoull(" - 8", &idx);
58 assert(false);
59 }
60 catch (const std::invalid_argument&)
61 {
62 assert(idx == 0);
63 }
64 try
65 {
66 std::stoull(L" - 8", &idx);
67 assert(false);
68 }
69 catch (const std::invalid_argument&)
70 {
71 assert(idx == 0);
72 }
73 try
74 {
75 std::stoull("a1", &idx);
76 assert(false);
77 }
78 catch (const std::invalid_argument&)
79 {
80 assert(idx == 0);
81 }
82 try
83 {
84 std::stoull(L"a1", &idx);
85 assert(false);
86 }
87 catch (const std::invalid_argument&)
88 {
89 assert(idx == 0);
90 }
Marshall Clowbf6eda02013-08-13 22:22:40 +000091// LWG issue #2009
Marshall Clow8634fc52013-08-13 15:52:51 +000092 try
93 {
94 std::stoull("9999999999999999999999999999999999999999999999999", &idx);
95 assert(false);
96 }
97 catch (const std::out_of_range&)
98 {
99 assert(idx == 0);
100 }
101 try
102 {
103 std::stoull(L"9999999999999999999999999999999999999999999999999", &idx);
104 assert(false);
105 }
106 catch (const std::out_of_range&)
107 {
108 assert(idx == 0);
109 }
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000110}