Coverage Report

Created: 2025-08-28 06:28

/src/llvm-project-18.1.8.build/include/c++/v1/stdexcept
Line
Count
Source (jump to first uncovered line)
1
// -*- C++ -*-
2
//===----------------------------------------------------------------------===//
3
//
4
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5
// See https://llvm.org/LICENSE.txt for license information.
6
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7
//
8
//===----------------------------------------------------------------------===//
9
10
#ifndef _LIBCPP_STDEXCEPT
11
#define _LIBCPP_STDEXCEPT
12
13
/*
14
    stdexcept synopsis
15
16
namespace std
17
{
18
19
class logic_error;
20
    class domain_error;
21
    class invalid_argument;
22
    class length_error;
23
    class out_of_range;
24
class runtime_error;
25
    class range_error;
26
    class overflow_error;
27
    class underflow_error;
28
29
for each class xxx_error:
30
31
class xxx_error : public exception // at least indirectly
32
{
33
public:
34
    explicit xxx_error(const string& what_arg);
35
    explicit xxx_error(const char*   what_arg);
36
37
    virtual const char* what() const noexcept // returns what_arg
38
};
39
40
}  // std
41
42
*/
43
44
#include <__assert> // all public C++ headers provide the assertion handler
45
#include <__config>
46
#include <__exception/exception.h>
47
#include <__fwd/string.h>
48
#include <__verbose_abort>
49
50
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
51
#  pragma GCC system_header
52
#endif
53
54
_LIBCPP_BEGIN_NAMESPACE_STD
55
56
#ifndef _LIBCPP_ABI_VCRUNTIME
57
class _LIBCPP_HIDDEN __libcpp_refstring {
58
  const char* __imp_;
59
60
  bool __uses_refcount() const;
61
62
public:
63
  explicit __libcpp_refstring(const char* __msg);
64
  __libcpp_refstring(const __libcpp_refstring& __s) _NOEXCEPT;
65
  __libcpp_refstring& operator=(const __libcpp_refstring& __s) _NOEXCEPT;
66
  ~__libcpp_refstring();
67
68
443k
  _LIBCPP_HIDE_FROM_ABI const char* c_str() const _NOEXCEPT { return __imp_; }
69
};
70
#endif // !_LIBCPP_ABI_VCRUNTIME
71
72
_LIBCPP_END_NAMESPACE_STD
73
74
namespace std // purposefully not using versioning namespace
75
{
76
77
class _LIBCPP_EXPORTED_FROM_ABI logic_error : public exception {
78
#ifndef _LIBCPP_ABI_VCRUNTIME
79
80
private:
81
  std::__libcpp_refstring __imp_;
82
83
public:
84
  explicit logic_error(const string&);
85
  explicit logic_error(const char*);
86
87
  logic_error(const logic_error&) _NOEXCEPT;
88
  logic_error& operator=(const logic_error&) _NOEXCEPT;
89
90
  ~logic_error() _NOEXCEPT override;
91
92
  const char* what() const _NOEXCEPT override;
93
#else
94
95
public:
96
  explicit logic_error(const std::string&); // Symbol uses versioned std::string
97
  _LIBCPP_HIDE_FROM_ABI explicit logic_error(const char* __s) : exception(__s) {}
98
#endif
99
};
100
101
class _LIBCPP_EXPORTED_FROM_ABI runtime_error : public exception {
102
#ifndef _LIBCPP_ABI_VCRUNTIME
103
104
private:
105
  std::__libcpp_refstring __imp_;
106
107
public:
108
  explicit runtime_error(const string&);
109
  explicit runtime_error(const char*);
110
111
  runtime_error(const runtime_error&) _NOEXCEPT;
112
  runtime_error& operator=(const runtime_error&) _NOEXCEPT;
113
114
  ~runtime_error() _NOEXCEPT override;
115
116
  const char* what() const _NOEXCEPT override;
117
#else
118
119
public:
120
  explicit runtime_error(const std::string&); // Symbol uses versioned std::string
121
  _LIBCPP_HIDE_FROM_ABI explicit runtime_error(const char* __s) : exception(__s) {}
122
#endif // _LIBCPP_ABI_VCRUNTIME
123
};
124
125
class _LIBCPP_EXPORTED_FROM_ABI domain_error : public logic_error {
126
public:
127
0
  _LIBCPP_HIDE_FROM_ABI explicit domain_error(const string& __s) : logic_error(__s) {}
128
0
  _LIBCPP_HIDE_FROM_ABI explicit domain_error(const char* __s) : logic_error(__s) {}
129
130
#ifndef _LIBCPP_ABI_VCRUNTIME
131
  _LIBCPP_HIDE_FROM_ABI domain_error(const domain_error&) _NOEXCEPT            = default;
132
  _LIBCPP_HIDE_FROM_ABI domain_error& operator=(const domain_error&) _NOEXCEPT = default;
133
  ~domain_error() _NOEXCEPT override;
134
#endif
135
};
136
137
class _LIBCPP_EXPORTED_FROM_ABI invalid_argument : public logic_error {
138
public:
139
0
  _LIBCPP_HIDE_FROM_ABI explicit invalid_argument(const string& __s) : logic_error(__s) {}
140
0
  _LIBCPP_HIDE_FROM_ABI explicit invalid_argument(const char* __s) : logic_error(__s) {}
141
142
#ifndef _LIBCPP_ABI_VCRUNTIME
143
  _LIBCPP_HIDE_FROM_ABI invalid_argument(const invalid_argument&) _NOEXCEPT            = default;
144
  _LIBCPP_HIDE_FROM_ABI invalid_argument& operator=(const invalid_argument&) _NOEXCEPT = default;
145
  ~invalid_argument() _NOEXCEPT override;
146
#endif
147
};
148
149
class _LIBCPP_EXPORTED_FROM_ABI length_error : public logic_error {
150
public:
151
0
  _LIBCPP_HIDE_FROM_ABI explicit length_error(const string& __s) : logic_error(__s) {}
152
0
  _LIBCPP_HIDE_FROM_ABI explicit length_error(const char* __s) : logic_error(__s) {}
153
#ifndef _LIBCPP_ABI_VCRUNTIME
154
  _LIBCPP_HIDE_FROM_ABI length_error(const length_error&) _NOEXCEPT            = default;
155
  _LIBCPP_HIDE_FROM_ABI length_error& operator=(const length_error&) _NOEXCEPT = default;
156
  ~length_error() _NOEXCEPT override;
157
#endif
158
};
159
160
class _LIBCPP_EXPORTED_FROM_ABI out_of_range : public logic_error {
161
public:
162
0
  _LIBCPP_HIDE_FROM_ABI explicit out_of_range(const string& __s) : logic_error(__s) {}
163
0
  _LIBCPP_HIDE_FROM_ABI explicit out_of_range(const char* __s) : logic_error(__s) {}
164
165
#ifndef _LIBCPP_ABI_VCRUNTIME
166
  _LIBCPP_HIDE_FROM_ABI out_of_range(const out_of_range&) _NOEXCEPT            = default;
167
  _LIBCPP_HIDE_FROM_ABI out_of_range& operator=(const out_of_range&) _NOEXCEPT = default;
168
  ~out_of_range() _NOEXCEPT override;
169
#endif
170
};
171
172
class _LIBCPP_EXPORTED_FROM_ABI range_error : public runtime_error {
173
public:
174
0
  _LIBCPP_HIDE_FROM_ABI explicit range_error(const string& __s) : runtime_error(__s) {}
175
0
  _LIBCPP_HIDE_FROM_ABI explicit range_error(const char* __s) : runtime_error(__s) {}
176
177
#ifndef _LIBCPP_ABI_VCRUNTIME
178
  _LIBCPP_HIDE_FROM_ABI range_error(const range_error&) _NOEXCEPT            = default;
179
  _LIBCPP_HIDE_FROM_ABI range_error& operator=(const range_error&) _NOEXCEPT = default;
180
  ~range_error() _NOEXCEPT override;
181
#endif
182
};
183
184
class _LIBCPP_EXPORTED_FROM_ABI overflow_error : public runtime_error {
185
public:
186
0
  _LIBCPP_HIDE_FROM_ABI explicit overflow_error(const string& __s) : runtime_error(__s) {}
187
0
  _LIBCPP_HIDE_FROM_ABI explicit overflow_error(const char* __s) : runtime_error(__s) {}
188
189
#ifndef _LIBCPP_ABI_VCRUNTIME
190
  _LIBCPP_HIDE_FROM_ABI overflow_error(const overflow_error&) _NOEXCEPT            = default;
191
  _LIBCPP_HIDE_FROM_ABI overflow_error& operator=(const overflow_error&) _NOEXCEPT = default;
192
  ~overflow_error() _NOEXCEPT override;
193
#endif
194
};
195
196
class _LIBCPP_EXPORTED_FROM_ABI underflow_error : public runtime_error {
197
public:
198
0
  _LIBCPP_HIDE_FROM_ABI explicit underflow_error(const string& __s) : runtime_error(__s) {}
199
0
  _LIBCPP_HIDE_FROM_ABI explicit underflow_error(const char* __s) : runtime_error(__s) {}
200
201
#ifndef _LIBCPP_ABI_VCRUNTIME
202
  _LIBCPP_HIDE_FROM_ABI underflow_error(const underflow_error&) _NOEXCEPT            = default;
203
  _LIBCPP_HIDE_FROM_ABI underflow_error& operator=(const underflow_error&) _NOEXCEPT = default;
204
  ~underflow_error() _NOEXCEPT override;
205
#endif
206
};
207
208
} // namespace std
209
210
_LIBCPP_BEGIN_NAMESPACE_STD
211
212
// in the dylib
213
_LIBCPP_NORETURN _LIBCPP_EXPORTED_FROM_ABI void __throw_runtime_error(const char*);
214
215
0
_LIBCPP_NORETURN inline _LIBCPP_HIDE_FROM_ABI void __throw_logic_error(const char* __msg) {
216
0
#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
217
0
  throw logic_error(__msg);
218
0
#else
219
0
  _LIBCPP_VERBOSE_ABORT("logic_error was thrown in -fno-exceptions mode with message \"%s\"", __msg);
220
0
#endif
221
0
}
222
223
0
_LIBCPP_NORETURN inline _LIBCPP_HIDE_FROM_ABI void __throw_domain_error(const char* __msg) {
224
0
#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
225
0
  throw domain_error(__msg);
226
0
#else
227
0
  _LIBCPP_VERBOSE_ABORT("domain_error was thrown in -fno-exceptions mode with message \"%s\"", __msg);
228
0
#endif
229
0
}
230
231
0
_LIBCPP_NORETURN inline _LIBCPP_HIDE_FROM_ABI void __throw_invalid_argument(const char* __msg) {
232
0
#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
233
0
  throw invalid_argument(__msg);
234
0
#else
235
0
  _LIBCPP_VERBOSE_ABORT("invalid_argument was thrown in -fno-exceptions mode with message \"%s\"", __msg);
236
0
#endif
237
0
}
238
239
0
_LIBCPP_NORETURN inline _LIBCPP_HIDE_FROM_ABI void __throw_length_error(const char* __msg) {
240
0
#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
241
0
  throw length_error(__msg);
242
0
#else
243
0
  _LIBCPP_VERBOSE_ABORT("length_error was thrown in -fno-exceptions mode with message \"%s\"", __msg);
244
0
#endif
245
0
}
246
247
0
_LIBCPP_NORETURN inline _LIBCPP_HIDE_FROM_ABI void __throw_out_of_range(const char* __msg) {
248
0
#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
249
0
  throw out_of_range(__msg);
250
0
#else
251
0
  _LIBCPP_VERBOSE_ABORT("out_of_range was thrown in -fno-exceptions mode with message \"%s\"", __msg);
252
0
#endif
253
0
}
254
255
0
_LIBCPP_NORETURN inline _LIBCPP_HIDE_FROM_ABI void __throw_range_error(const char* __msg) {
256
0
#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
257
0
  throw range_error(__msg);
258
0
#else
259
0
  _LIBCPP_VERBOSE_ABORT("range_error was thrown in -fno-exceptions mode with message \"%s\"", __msg);
260
0
#endif
261
0
}
262
263
0
_LIBCPP_NORETURN inline _LIBCPP_HIDE_FROM_ABI void __throw_overflow_error(const char* __msg) {
264
0
#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
265
0
  throw overflow_error(__msg);
266
0
#else
267
0
  _LIBCPP_VERBOSE_ABORT("overflow_error was thrown in -fno-exceptions mode with message \"%s\"", __msg);
268
0
#endif
269
0
}
270
271
0
_LIBCPP_NORETURN inline _LIBCPP_HIDE_FROM_ABI void __throw_underflow_error(const char* __msg) {
272
0
#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
273
0
  throw underflow_error(__msg);
274
0
#else
275
0
  _LIBCPP_VERBOSE_ABORT("underflow_error was thrown in -fno-exceptions mode with message \"%s\"", __msg);
276
0
#endif
277
0
}
278
279
_LIBCPP_END_NAMESPACE_STD
280
281
#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
282
#  include <cstdlib>
283
#  include <exception>
284
#  include <iosfwd>
285
#endif
286
287
#endif // _LIBCPP_STDEXCEPT