1// -*- C++ -*- 2//===----------------------------- new ------------------------------------===// 3// 4// The LLVM Compiler Infrastructure 5// 6// This file is dual licensed under the MIT and the University of Illinois Open 7// Source Licenses. See LICENSE.TXT for details. 8// 9//===----------------------------------------------------------------------===// 10 11#ifndef _LIBCPP_NEW 12#define _LIBCPP_NEW 13 14/* 15 new synopsis 16 17namespace std 18{ 19 20class bad_alloc 21 : public exception 22{ 23public: 24 bad_alloc() noexcept; 25 bad_alloc(const bad_alloc&) noexcept; 26 bad_alloc& operator=(const bad_alloc&) noexcept; 27 virtual const char* what() const noexcept; 28}; 29 30class bad_array_length : public bad_alloc // C++14 31{ 32public: 33 bad_array_length() noexcept; 34}; 35 36class bad_array_new_length : public bad_alloc 37{ 38public: 39 bad_array_new_length() noexcept; 40}; 41 42struct nothrow_t {}; 43extern const nothrow_t nothrow; 44typedef void (*new_handler)(); 45new_handler set_new_handler(new_handler new_p) noexcept; 46new_handler get_new_handler() noexcept; 47 48} // std 49 50void* operator new(std::size_t size); // replaceable 51void* operator new(std::size_t size, const std::nothrow_t&) noexcept; // replaceable 52void operator delete(void* ptr) noexcept; // replaceable 53void operator delete(void* ptr, const std::nothrow_t&) noexcept; // replaceable 54 55void* operator new[](std::size_t size); // replaceable 56void* operator new[](std::size_t size, const std::nothrow_t&) noexcept; // replaceable 57void operator delete[](void* ptr) noexcept; // replaceable 58void operator delete[](void* ptr, const std::nothrow_t&) noexcept; // replaceable 59 60void* operator new (std::size_t size, void* ptr) noexcept; 61void* operator new[](std::size_t size, void* ptr) noexcept; 62void operator delete (void* ptr, void*) noexcept; 63void operator delete[](void* ptr, void*) noexcept; 64 65*/ 66 67#include <__config> 68#include <exception> 69#include <cstddef> 70 71#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 72#pragma GCC system_header 73#endif 74 75namespace std // purposefully not using versioning namespace 76{ 77 78class _LIBCPP_EXCEPTION_ABI bad_alloc 79 : public exception 80{ 81public: 82 bad_alloc() _NOEXCEPT; 83 virtual ~bad_alloc() _NOEXCEPT; 84 virtual const char* what() const _NOEXCEPT; 85}; 86 87class _LIBCPP_EXCEPTION_ABI bad_array_new_length 88 : public bad_alloc 89{ 90public: 91 bad_array_new_length() _NOEXCEPT; 92 virtual ~bad_array_new_length() _NOEXCEPT; 93 virtual const char* what() const _NOEXCEPT; 94}; 95 96#if defined(_LIBCPP_BUILDING_NEW) || (_LIBCPP_STD_VER > 11) 97class _LIBCPP_EXCEPTION_ABI bad_array_length 98 : public bad_alloc 99{ 100public: 101 bad_array_length() _NOEXCEPT; 102 virtual ~bad_array_length() _NOEXCEPT; 103 virtual const char* what() const _NOEXCEPT; 104}; 105#endif 106 107_LIBCPP_FUNC_VIS void __throw_bad_alloc(); // not in C++ spec 108 109struct _LIBCPP_TYPE_VIS nothrow_t {}; 110extern _LIBCPP_FUNC_VIS const nothrow_t nothrow; 111typedef void (*new_handler)(); 112_LIBCPP_FUNC_VIS new_handler set_new_handler(new_handler) _NOEXCEPT; 113_LIBCPP_FUNC_VIS new_handler get_new_handler() _NOEXCEPT; 114 115} // std 116 117#if defined(_WIN32) && !defined(cxx_EXPORTS) 118# define _LIBCPP_NEW_DELETE_VIS _LIBCPP_FUNC_VIS_ONLY 119#else 120# define _LIBCPP_NEW_DELETE_VIS _LIBCPP_FUNC_VIS 121#endif 122 123_LIBCPP_NEW_DELETE_VIS void* operator new(std::size_t __sz) 124#if !__has_feature(cxx_noexcept) 125 throw(std::bad_alloc) 126#endif 127; 128_LIBCPP_NEW_DELETE_VIS void* operator new(std::size_t __sz, const std::nothrow_t&) _NOEXCEPT _NOALIAS; 129_LIBCPP_NEW_DELETE_VIS void operator delete(void* __p) _NOEXCEPT; 130_LIBCPP_NEW_DELETE_VIS void operator delete(void* __p, const std::nothrow_t&) _NOEXCEPT; 131 132_LIBCPP_NEW_DELETE_VIS void* operator new[](std::size_t __sz) 133#if !__has_feature(cxx_noexcept) 134 throw(std::bad_alloc) 135#endif 136; 137_LIBCPP_NEW_DELETE_VIS void* operator new[](std::size_t __sz, const std::nothrow_t&) _NOEXCEPT _NOALIAS; 138_LIBCPP_NEW_DELETE_VIS void operator delete[](void* __p) _NOEXCEPT; 139_LIBCPP_NEW_DELETE_VIS void operator delete[](void* __p, const std::nothrow_t&) _NOEXCEPT; 140 141inline _LIBCPP_INLINE_VISIBILITY void* operator new (std::size_t, void* __p) _NOEXCEPT {return __p;} 142inline _LIBCPP_INLINE_VISIBILITY void* operator new[](std::size_t, void* __p) _NOEXCEPT {return __p;} 143inline _LIBCPP_INLINE_VISIBILITY void operator delete (void*, void*) _NOEXCEPT {} 144inline _LIBCPP_INLINE_VISIBILITY void operator delete[](void*, void*) _NOEXCEPT {} 145 146#endif // _LIBCPP_NEW 147