summaryrefslogtreecommitdiffstats
path: root/contrib/libc++/include/new
blob: 1e85798b5c461089ed9245b32ad888597fc89f12 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// -*- C++ -*-
//===----------------------------- new ------------------------------------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#ifndef _LIBCPP_NEW
#define _LIBCPP_NEW

/*
    new synopsis

namespace std
{

class bad_alloc
    : public exception
{
public:
    bad_alloc() noexcept;
    bad_alloc(const bad_alloc&) noexcept;
    bad_alloc& operator=(const bad_alloc&) noexcept;
    virtual const char* what() const noexcept;
};

struct nothrow_t {};
extern const nothrow_t nothrow;
typedef void (*new_handler)();
new_handler set_new_handler(new_handler new_p) noexcept;
new_handler get_new_handler() noexcept;

}  // std

void* operator new(std::size_t size);                                   // replaceable
void* operator new(std::size_t size, const std::nothrow_t&) noexcept;   // replaceable
void  operator delete(void* ptr) noexcept;                              // replaceable
void  operator delete(void* ptr, const std::nothrow_t&) noexcept;       // replaceable

void* operator new[](std::size_t size);                                 // replaceable
void* operator new[](std::size_t size, const std::nothrow_t&) noexcept; // replaceable
void  operator delete[](void* ptr) noexcept;                            // replaceable
void  operator delete[](void* ptr, const std::nothrow_t&) noexcept;     // replaceable

void* operator new  (std::size_t size, void* ptr) noexcept;
void* operator new[](std::size_t size, void* ptr) noexcept;
void  operator delete  (void* ptr, void*) noexcept;
void  operator delete[](void* ptr, void*) noexcept;

*/

#include <__config>
#include <exception>
#include <cstddef>

#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif

namespace std  // purposefully not using versioning namespace
{

class _LIBCPP_EXCEPTION_ABI bad_alloc
    : public exception
{
public:
    bad_alloc() _NOEXCEPT;
    virtual ~bad_alloc() _NOEXCEPT;
    virtual const char* what() const _NOEXCEPT;
};

class _LIBCPP_EXCEPTION_ABI bad_array_new_length
    : public bad_alloc
{
public:
    bad_array_new_length() _NOEXCEPT;
    virtual ~bad_array_new_length() _NOEXCEPT;
    virtual const char* what() const _NOEXCEPT;
};

void __throw_bad_alloc();  // not in C++ spec

struct _LIBCPP_TYPE_VIS nothrow_t {};
extern _LIBCPP_FUNC_VIS const nothrow_t nothrow;
typedef void (*new_handler)();
_LIBCPP_FUNC_VIS new_handler set_new_handler(new_handler) _NOEXCEPT;
_LIBCPP_FUNC_VIS new_handler get_new_handler() _NOEXCEPT;

}  // std

_LIBCPP_FUNC_VIS void* operator new(std::size_t __sz)
#if !__has_feature(cxx_noexcept)
    throw(std::bad_alloc)
#endif
;
_LIBCPP_FUNC_VIS void* operator new(std::size_t __sz, const std::nothrow_t&) _NOEXCEPT _NOALIAS;
_LIBCPP_FUNC_VIS void  operator delete(void* __p) _NOEXCEPT;
_LIBCPP_FUNC_VIS void  operator delete(void* __p, const std::nothrow_t&) _NOEXCEPT;

_LIBCPP_FUNC_VIS void* operator new[](std::size_t __sz)
#if !__has_feature(cxx_noexcept)
    throw(std::bad_alloc)
#endif
;
_LIBCPP_FUNC_VIS void* operator new[](std::size_t __sz, const std::nothrow_t&) _NOEXCEPT _NOALIAS;
_LIBCPP_FUNC_VIS void  operator delete[](void* __p) _NOEXCEPT;
_LIBCPP_FUNC_VIS void  operator delete[](void* __p, const std::nothrow_t&) _NOEXCEPT;

_LIBCPP_INLINE_VISIBILITY inline void* operator new  (std::size_t, void* __p) _NOEXCEPT {return __p;}
_LIBCPP_INLINE_VISIBILITY inline void* operator new[](std::size_t, void* __p) _NOEXCEPT {return __p;}
_LIBCPP_INLINE_VISIBILITY inline void  operator delete  (void*, void*) _NOEXCEPT {}
_LIBCPP_INLINE_VISIBILITY inline void  operator delete[](void*, void*) _NOEXCEPT {}

#endif  // _LIBCPP_NEW
OpenPOWER on IntegriCloud