]>
Commit | Line | Data |
---|---|---|
6305f20a | 1 | // The -*- C++ -*- dynamic memory management header. |
0c952af3 | 2 | |
818ab71a | 3 | // Copyright (C) 1994-2016 Free Software Foundation, Inc. |
6305f20a | 4 | |
cbecceb9 | 5 | // This file is part of GCC. |
6305f20a | 6 | // |
cbecceb9 | 7 | // GCC is free software; you can redistribute it and/or modify |
6305f20a | 8 | // it under the terms of the GNU General Public License as published by |
748086b7 | 9 | // the Free Software Foundation; either version 3, or (at your option) |
6305f20a BK |
10 | // any later version. |
11 | // | |
cbecceb9 | 12 | // GCC is distributed in the hope that it will be useful, |
6305f20a BK |
13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | // GNU General Public License for more details. | |
16 | // | |
748086b7 JJ |
17 | // Under Section 7 of GPL version 3, you are granted additional |
18 | // permissions described in the GCC Runtime Library Exception, version | |
19 | // 3.1, as published by the Free Software Foundation. | |
20 | ||
21 | // You should have received a copy of the GNU General Public License and | |
22 | // a copy of the GCC Runtime Library Exception along with this program; | |
23 | // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see | |
24 | // <http://www.gnu.org/licenses/>. | |
6305f20a | 25 | |
669f7a03 | 26 | /** @file new |
78a53887 BK |
27 | * This is a Standard C++ Library header. |
28 | * | |
ffe94f83 | 29 | * The header @c new defines several functions to manage dynamic memory and |
669f7a03 PE |
30 | * handling memory allocation errors; see |
31 | * http://gcc.gnu.org/onlinedocs/libstdc++/18_support/howto.html#4 for more. | |
32 | */ | |
33 | ||
3d7c150e BK |
34 | #ifndef _NEW |
35 | #define _NEW | |
6305f20a | 36 | |
584fd146 PC |
37 | #pragma GCC system_header |
38 | ||
8fc81078 | 39 | #include <bits/c++config.h> |
6305f20a BK |
40 | #include <exception> |
41 | ||
723acbd5 MM |
42 | #pragma GCC visibility push(default) |
43 | ||
6305f20a BK |
44 | extern "C++" { |
45 | ||
0c952af3 BK |
46 | namespace std |
47 | { | |
aa2d5ba2 PE |
48 | /** |
49 | * @brief Exception possibly thrown by @c new. | |
5b9daa7e | 50 | * @ingroup exceptions |
aa2d5ba2 PE |
51 | * |
52 | * @c bad_alloc (or classes derived from it) is used to report allocation | |
669f7a03 | 53 | * errors from the throwing forms of @c new. */ |
0c952af3 BK |
54 | class bad_alloc : public exception |
55 | { | |
6305f20a | 56 | public: |
f68147f7 | 57 | bad_alloc() throw() { } |
949d9ae1 | 58 | |
e05cd3dd PC |
59 | // This declaration is not useless: |
60 | // http://gcc.gnu.org/onlinedocs/gcc-3.0.2/gcc_6.html#SEC118 | |
d66ae36a | 61 | virtual ~bad_alloc() throw(); |
949d9ae1 | 62 | |
c3f0f556 PC |
63 | // See comment in eh_exception.cc. |
64 | virtual const char* what() const throw(); | |
6305f20a BK |
65 | }; |
66 | ||
7d5e76c8 JM |
67 | #if __cplusplus >= 201103L |
68 | class bad_array_new_length : public bad_alloc | |
69 | { | |
70 | public: | |
71 | bad_array_new_length() throw() { }; | |
72 | ||
73 | // This declaration is not useless: | |
74 | // http://gcc.gnu.org/onlinedocs/gcc-3.0.2/gcc_6.html#SEC118 | |
75 | virtual ~bad_array_new_length() throw(); | |
76 | ||
77 | // See comment in eh_exception.cc. | |
78 | virtual const char* what() const throw(); | |
79 | }; | |
80 | #endif | |
81 | ||
af63ba4b JM |
82 | #if __cpp_aligned_new |
83 | enum class align_val_t: size_t {}; | |
84 | #endif | |
85 | ||
269fa2a9 VV |
86 | struct nothrow_t |
87 | { | |
88 | #if __cplusplus >= 201103L | |
89 | explicit nothrow_t() = default; | |
90 | #endif | |
91 | }; | |
949d9ae1 | 92 | |
6305f20a | 93 | extern const nothrow_t nothrow; |
949d9ae1 | 94 | |
669f7a03 PE |
95 | /** If you write your own error handler to be called by @c new, it must |
96 | * be of this type. */ | |
6305f20a | 97 | typedef void (*new_handler)(); |
949d9ae1 BK |
98 | |
99 | /// Takes a replacement handler as the argument, returns the | |
100 | /// previous handler. | |
984812cd | 101 | new_handler set_new_handler(new_handler) throw(); |
dca77a8a JW |
102 | |
103 | #if __cplusplus >= 201103L | |
104 | /// Return the current new handler. | |
105 | new_handler get_new_handler() noexcept; | |
106 | #endif | |
6305f20a BK |
107 | } // namespace std |
108 | ||
669f7a03 PE |
109 | //@{ |
110 | /** These are replaceable signatures: | |
111 | * - normal single new and delete (no arguments, throw @c bad_alloc on error) | |
112 | * - normal array new and delete (same) | |
113 | * - @c nothrow single new and delete (take a @c nothrow argument, return | |
114 | * @c NULL on error) | |
115 | * - @c nothrow array new and delete (same) | |
116 | * | |
117 | * Placement new and delete signatures (take a memory address argument, | |
118 | * does nothing) may not be replaced by a user's program. | |
119 | */ | |
578f0234 PC |
120 | void* operator new(std::size_t) _GLIBCXX_THROW (std::bad_alloc) |
121 | __attribute__((__externally_visible__)); | |
122 | void* operator new[](std::size_t) _GLIBCXX_THROW (std::bad_alloc) | |
123 | __attribute__((__externally_visible__)); | |
124 | void operator delete(void*) _GLIBCXX_USE_NOEXCEPT | |
125 | __attribute__((__externally_visible__)); | |
126 | void operator delete[](void*) _GLIBCXX_USE_NOEXCEPT | |
127 | __attribute__((__externally_visible__)); | |
34148d68 JM |
128 | #if __cpp_sized_deallocation |
129 | void operator delete(void*, std::size_t) _GLIBCXX_USE_NOEXCEPT | |
130 | __attribute__((__externally_visible__)); | |
131 | void operator delete[](void*, std::size_t) _GLIBCXX_USE_NOEXCEPT | |
132 | __attribute__((__externally_visible__)); | |
133 | #endif | |
578f0234 PC |
134 | void* operator new(std::size_t, const std::nothrow_t&) _GLIBCXX_USE_NOEXCEPT |
135 | __attribute__((__externally_visible__)); | |
136 | void* operator new[](std::size_t, const std::nothrow_t&) _GLIBCXX_USE_NOEXCEPT | |
137 | __attribute__((__externally_visible__)); | |
138 | void operator delete(void*, const std::nothrow_t&) _GLIBCXX_USE_NOEXCEPT | |
139 | __attribute__((__externally_visible__)); | |
140 | void operator delete[](void*, const std::nothrow_t&) _GLIBCXX_USE_NOEXCEPT | |
141 | __attribute__((__externally_visible__)); | |
af63ba4b JM |
142 | #if __cpp_aligned_new |
143 | void* operator new(std::size_t, std::align_val_t) | |
144 | __attribute__((__externally_visible__)); | |
145 | void* operator new(std::size_t, std::align_val_t, const std::nothrow_t&) | |
146 | _GLIBCXX_USE_NOEXCEPT __attribute__((__externally_visible__)); | |
147 | void operator delete(void*, std::align_val_t) | |
148 | _GLIBCXX_USE_NOEXCEPT __attribute__((__externally_visible__)); | |
149 | void operator delete(void*, std::align_val_t, const std::nothrow_t&) | |
150 | _GLIBCXX_USE_NOEXCEPT __attribute__((__externally_visible__)); | |
151 | void* operator new[](std::size_t, std::align_val_t) | |
152 | __attribute__((__externally_visible__)); | |
153 | void* operator new[](std::size_t, std::align_val_t, const std::nothrow_t&) | |
154 | _GLIBCXX_USE_NOEXCEPT __attribute__((__externally_visible__)); | |
155 | void operator delete[](void*, std::align_val_t) | |
156 | _GLIBCXX_USE_NOEXCEPT __attribute__((__externally_visible__)); | |
157 | void operator delete[](void*, std::align_val_t, const std::nothrow_t&) | |
158 | _GLIBCXX_USE_NOEXCEPT __attribute__((__externally_visible__)); | |
159 | #if __cpp_sized_deallocation | |
160 | void operator delete(void*, std::size_t, std::align_val_t) | |
161 | _GLIBCXX_USE_NOEXCEPT __attribute__((__externally_visible__)); | |
162 | void operator delete[](void*, std::size_t, std::align_val_t) | |
163 | _GLIBCXX_USE_NOEXCEPT __attribute__((__externally_visible__)); | |
164 | #endif // __cpp_sized_deallocation | |
165 | #endif // __cpp_aligned_new | |
6305f20a | 166 | |
0c952af3 | 167 | // Default placement versions of operator new. |
578f0234 PC |
168 | inline void* operator new(std::size_t, void* __p) _GLIBCXX_USE_NOEXCEPT |
169 | { return __p; } | |
170 | inline void* operator new[](std::size_t, void* __p) _GLIBCXX_USE_NOEXCEPT | |
171 | { return __p; } | |
51937d2c BK |
172 | |
173 | // Default placement versions of operator delete. | |
578f0234 PC |
174 | inline void operator delete (void*, void*) _GLIBCXX_USE_NOEXCEPT { } |
175 | inline void operator delete[](void*, void*) _GLIBCXX_USE_NOEXCEPT { } | |
669f7a03 | 176 | //@} |
6305f20a BK |
177 | } // extern "C++" |
178 | ||
723acbd5 MM |
179 | #pragma GCC visibility pop |
180 | ||
6305f20a | 181 | #endif |