blob: 70563d9be51f8dc0f8cbd62f5e90f0bb9b0f70aa [file] [log] [blame]
Howard Hinnantcbbf6332010-06-02 18:20:39 +00001//===----------------------------------------------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Howard Hinnant412dbeb2010-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 Hinnantcbbf6332010-06-02 18:20:39 +00007//
8//===----------------------------------------------------------------------===//
Howard Hinnant56c917c2013-08-22 00:04:22 +00009//
Mehdi Aminif8764e302017-03-15 00:59:54 +000010// XFAIL: with_system_cxx_lib=x86_64-apple-macosx10.7
11// XFAIL: with_system_cxx_lib=x86_64-apple-macosx10.8
Howard Hinnantcbbf6332010-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
Roger Ferrer Ibanez84c152a2016-11-14 10:44:26 +000021#include "test_macros.h"
22
Howard Hinnantcbbf6332010-06-02 18:20:39 +000023int main()
24{
25 assert(std::stoull("0") == 0);
26 assert(std::stoull(L"0") == 0);
27 assert(std::stoull("-0") == 0);
28 assert(std::stoull(L"-0") == 0);
29 assert(std::stoull(" 10") == 10);
30 assert(std::stoull(L" 10") == 10);
31 size_t idx = 0;
32 assert(std::stoull("10g", &idx, 16) == 16);
33 assert(idx == 2);
34 idx = 0;
35 assert(std::stoull(L"10g", &idx, 16) == 16);
36 assert(idx == 2);
Roger Ferrer Ibanez84c152a2016-11-14 10:44:26 +000037#ifndef TEST_HAS_NO_EXCEPTIONS
Howard Hinnantcbbf6332010-06-02 18:20:39 +000038 idx = 0;
39 try
40 {
41 std::stoull("", &idx);
42 assert(false);
43 }
44 catch (const std::invalid_argument&)
45 {
46 assert(idx == 0);
47 }
48 idx = 0;
49 try
50 {
51 std::stoull(L"", &idx);
52 assert(false);
53 }
54 catch (const std::invalid_argument&)
55 {
56 assert(idx == 0);
57 }
58 try
59 {
60 std::stoull(" - 8", &idx);
61 assert(false);
62 }
63 catch (const std::invalid_argument&)
64 {
65 assert(idx == 0);
66 }
67 try
68 {
69 std::stoull(L" - 8", &idx);
70 assert(false);
71 }
72 catch (const std::invalid_argument&)
73 {
74 assert(idx == 0);
75 }
76 try
77 {
78 std::stoull("a1", &idx);
79 assert(false);
80 }
81 catch (const std::invalid_argument&)
82 {
83 assert(idx == 0);
84 }
85 try
86 {
87 std::stoull(L"a1", &idx);
88 assert(false);
89 }
90 catch (const std::invalid_argument&)
91 {
92 assert(idx == 0);
93 }
Marshall Clowe4fa0de2013-08-13 22:22:40 +000094// LWG issue #2009
Marshall Clow914993d2013-08-13 15:52:51 +000095 try
96 {
97 std::stoull("9999999999999999999999999999999999999999999999999", &idx);
98 assert(false);
99 }
100 catch (const std::out_of_range&)
101 {
102 assert(idx == 0);
103 }
104 try
105 {
106 std::stoull(L"9999999999999999999999999999999999999999999999999", &idx);
107 assert(false);
108 }
109 catch (const std::out_of_range&)
110 {
111 assert(idx == 0);
112 }
Roger Ferrer Ibanez84c152a2016-11-14 10:44:26 +0000113#endif
Howard Hinnantcbbf6332010-06-02 18:20:39 +0000114}