Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-03 08:13:57

0001 //===----------------------------------------------------------------------===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef _LIBCPP___NEW_EXCEPTIONS_H
0010 #define _LIBCPP___NEW_EXCEPTIONS_H
0011 
0012 #include <__config>
0013 #include <__exception/exception.h>
0014 #include <__verbose_abort>
0015 
0016 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0017 #  pragma GCC system_header
0018 #endif
0019 
0020 // purposefully not using versioning namespace
0021 namespace std {
0022 #if !defined(_LIBCPP_ABI_VCRUNTIME)
0023 
0024 class _LIBCPP_EXPORTED_FROM_ABI bad_alloc : public exception {
0025 public:
0026   bad_alloc() _NOEXCEPT;
0027   _LIBCPP_HIDE_FROM_ABI bad_alloc(const bad_alloc&) _NOEXCEPT            = default;
0028   _LIBCPP_HIDE_FROM_ABI bad_alloc& operator=(const bad_alloc&) _NOEXCEPT = default;
0029   ~bad_alloc() _NOEXCEPT override;
0030   const char* what() const _NOEXCEPT override;
0031 };
0032 
0033 class _LIBCPP_EXPORTED_FROM_ABI bad_array_new_length : public bad_alloc {
0034 public:
0035   bad_array_new_length() _NOEXCEPT;
0036   _LIBCPP_HIDE_FROM_ABI bad_array_new_length(const bad_array_new_length&) _NOEXCEPT            = default;
0037   _LIBCPP_HIDE_FROM_ABI bad_array_new_length& operator=(const bad_array_new_length&) _NOEXCEPT = default;
0038   ~bad_array_new_length() _NOEXCEPT override;
0039   const char* what() const _NOEXCEPT override;
0040 };
0041 
0042 #elif defined(_HAS_EXCEPTIONS) && _HAS_EXCEPTIONS == 0 // !_LIBCPP_ABI_VCRUNTIME
0043 
0044 // When _HAS_EXCEPTIONS == 0, these complete definitions are needed,
0045 // since they would normally be provided in vcruntime_exception.h
0046 class bad_alloc : public exception {
0047 public:
0048   bad_alloc() noexcept : exception("bad allocation") {}
0049 
0050 private:
0051   friend class bad_array_new_length;
0052 
0053   bad_alloc(char const* const __message) noexcept : exception(__message) {}
0054 };
0055 
0056 class bad_array_new_length : public bad_alloc {
0057 public:
0058   bad_array_new_length() noexcept : bad_alloc("bad array new length") {}
0059 };
0060 
0061 #endif // defined(_LIBCPP_ABI_VCRUNTIME) && defined(_HAS_EXCEPTIONS) && _HAS_EXCEPTIONS == 0
0062 
0063 [[__noreturn__]] _LIBCPP_EXPORTED_FROM_ABI void __throw_bad_alloc(); // not in C++ spec
0064 
0065 [[__noreturn__]] inline _LIBCPP_HIDE_FROM_ABI void __throw_bad_array_new_length() {
0066 #if _LIBCPP_HAS_EXCEPTIONS
0067   throw bad_array_new_length();
0068 #else
0069   _LIBCPP_VERBOSE_ABORT("bad_array_new_length was thrown in -fno-exceptions mode");
0070 #endif
0071 }
0072 } // namespace std
0073 
0074 #endif // _LIBCPP___NEW_EXCEPTIONS_H