Path: blob/main/contrib/llvm-project/libcxx/include/__new/exceptions.h
213766 views
//===----------------------------------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#ifndef _LIBCPP___NEW_EXCEPTIONS_H9#define _LIBCPP___NEW_EXCEPTIONS_H1011#include <__config>12#include <__exception/exception.h>13#include <__verbose_abort>1415#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)16# pragma GCC system_header17#endif1819_LIBCPP_BEGIN_UNVERSIONED_NAMESPACE_STD20#if !defined(_LIBCPP_ABI_VCRUNTIME)2122class _LIBCPP_EXPORTED_FROM_ABI bad_alloc : public exception {23public:24bad_alloc() _NOEXCEPT;25_LIBCPP_HIDE_FROM_ABI bad_alloc(const bad_alloc&) _NOEXCEPT = default;26_LIBCPP_HIDE_FROM_ABI bad_alloc& operator=(const bad_alloc&) _NOEXCEPT = default;27~bad_alloc() _NOEXCEPT override;28const char* what() const _NOEXCEPT override;29};3031class _LIBCPP_EXPORTED_FROM_ABI bad_array_new_length : public bad_alloc {32public:33bad_array_new_length() _NOEXCEPT;34_LIBCPP_HIDE_FROM_ABI bad_array_new_length(const bad_array_new_length&) _NOEXCEPT = default;35_LIBCPP_HIDE_FROM_ABI bad_array_new_length& operator=(const bad_array_new_length&) _NOEXCEPT = default;36~bad_array_new_length() _NOEXCEPT override;37const char* what() const _NOEXCEPT override;38};3940#elif defined(_HAS_EXCEPTIONS) && _HAS_EXCEPTIONS == 0 // !_LIBCPP_ABI_VCRUNTIME4142// When _HAS_EXCEPTIONS == 0, these complete definitions are needed,43// since they would normally be provided in vcruntime_exception.h44class bad_alloc : public exception {45public:46bad_alloc() noexcept : exception("bad allocation") {}4748private:49friend class bad_array_new_length;5051bad_alloc(char const* const __message) noexcept : exception(__message) {}52};5354class bad_array_new_length : public bad_alloc {55public:56bad_array_new_length() noexcept : bad_alloc("bad array new length") {}57};5859#endif // defined(_LIBCPP_ABI_VCRUNTIME) && defined(_HAS_EXCEPTIONS) && _HAS_EXCEPTIONS == 06061[[__noreturn__]] _LIBCPP_EXPORTED_FROM_ABI void __throw_bad_alloc(); // not in C++ spec6263[[__noreturn__]] inline _LIBCPP_HIDE_FROM_ABI void __throw_bad_array_new_length() {64#if _LIBCPP_HAS_EXCEPTIONS65throw bad_array_new_length();66#else67_LIBCPP_VERBOSE_ABORT("bad_array_new_length was thrown in -fno-exceptions mode");68#endif69}70_LIBCPP_END_UNVERSIONED_NAMESPACE_STD7172#endif // _LIBCPP___NEW_EXCEPTIONS_H737475