s/requires/REQUIRES to fix the test on release build
[llvm-project.git] / libcxx / include / __new / exceptions.h
blob053feecb0367878dd6a4301117ede76fe9ac0332
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #ifndef _LIBCPP___NEW_EXCEPTIONS_H
10 #define _LIBCPP___NEW_EXCEPTIONS_H
12 #include <__config>
13 #include <__exception/exception.h>
14 #include <__verbose_abort>
16 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17 # pragma GCC system_header
18 #endif
20 // purposefully not using versioning namespace
21 namespace std {
22 #if !defined(_LIBCPP_ABI_VCRUNTIME)
24 class _LIBCPP_EXPORTED_FROM_ABI bad_alloc : public exception {
25 public:
26 bad_alloc() _NOEXCEPT;
27 _LIBCPP_HIDE_FROM_ABI bad_alloc(const bad_alloc&) _NOEXCEPT = default;
28 _LIBCPP_HIDE_FROM_ABI bad_alloc& operator=(const bad_alloc&) _NOEXCEPT = default;
29 ~bad_alloc() _NOEXCEPT override;
30 const char* what() const _NOEXCEPT override;
33 class _LIBCPP_EXPORTED_FROM_ABI bad_array_new_length : public bad_alloc {
34 public:
35 bad_array_new_length() _NOEXCEPT;
36 _LIBCPP_HIDE_FROM_ABI bad_array_new_length(const bad_array_new_length&) _NOEXCEPT = default;
37 _LIBCPP_HIDE_FROM_ABI bad_array_new_length& operator=(const bad_array_new_length&) _NOEXCEPT = default;
38 ~bad_array_new_length() _NOEXCEPT override;
39 const char* what() const _NOEXCEPT override;
42 #elif defined(_HAS_EXCEPTIONS) && _HAS_EXCEPTIONS == 0 // !_LIBCPP_ABI_VCRUNTIME
44 // When _HAS_EXCEPTIONS == 0, these complete definitions are needed,
45 // since they would normally be provided in vcruntime_exception.h
46 class bad_alloc : public exception {
47 public:
48 bad_alloc() noexcept : exception("bad allocation") {}
50 private:
51 friend class bad_array_new_length;
53 bad_alloc(char const* const __message) noexcept : exception(__message) {}
56 class bad_array_new_length : public bad_alloc {
57 public:
58 bad_array_new_length() noexcept : bad_alloc("bad array new length") {}
61 #endif // defined(_LIBCPP_ABI_VCRUNTIME) && defined(_HAS_EXCEPTIONS) && _HAS_EXCEPTIONS == 0
63 [[__noreturn__]] _LIBCPP_EXPORTED_FROM_ABI void __throw_bad_alloc(); // not in C++ spec
65 [[__noreturn__]] inline _LIBCPP_HIDE_FROM_ABI void __throw_bad_array_new_length() {
66 #if _LIBCPP_HAS_EXCEPTIONS
67 throw bad_array_new_length();
68 #else
69 _LIBCPP_VERBOSE_ABORT("bad_array_new_length was thrown in -fno-exceptions mode");
70 #endif
72 } // namespace std
74 #endif // _LIBCPP___NEW_EXCEPTIONS_H