]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/libsupc++/new
Daily bump.
[thirdparty/gcc.git] / libstdc++-v3 / libsupc++ / new
CommitLineData
6305f20a 1// The -*- C++ -*- dynamic memory management header.
0c952af3 2
c3f0f556
PC
3// Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
4// 2003, 2004, 2005, 2006, 2007
d66ae36a 5// Free Software Foundation
6305f20a 6
cbecceb9 7// This file is part of GCC.
6305f20a 8//
cbecceb9 9// GCC is free software; you can redistribute it and/or modify
6305f20a
BK
10// it under the terms of the GNU General Public License as published by
11// the Free Software Foundation; either version 2, or (at your option)
12// any later version.
13//
cbecceb9 14// GCC is distributed in the hope that it will be useful,
6305f20a
BK
15// but WITHOUT ANY WARRANTY; without even the implied warranty of
16// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17// GNU General Public License for more details.
18//
19// You should have received a copy of the GNU General Public License
cbecceb9 20// along with GCC; see the file COPYING. If not, write to
83f51799
KC
21// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
22// Boston, MA 02110-1301, USA.
6305f20a
BK
23
24// As a special exception, you may use this file as part of a free software
25// library without restriction. Specifically, if other files instantiate
26// templates or use macros or inline functions from this file, or you compile
27// this file and link it with other files to produce an executable, this
28// file does not by itself cause the resulting executable to be covered by
29// the GNU General Public License. This exception does not however
30// invalidate any other reasons why the executable file might be covered by
31// the GNU General Public License.
32
669f7a03 33/** @file new
78a53887
BK
34 * This is a Standard C++ Library header.
35 *
ffe94f83 36 * The header @c new defines several functions to manage dynamic memory and
669f7a03
PE
37 * handling memory allocation errors; see
38 * http://gcc.gnu.org/onlinedocs/libstdc++/18_support/howto.html#4 for more.
39 */
40
3d7c150e
BK
41#ifndef _NEW
42#define _NEW
6305f20a 43
6305f20a 44#include <cstddef>
6305f20a
BK
45#include <exception>
46
723acbd5
MM
47#pragma GCC visibility push(default)
48
6305f20a
BK
49extern "C++" {
50
0c952af3
BK
51namespace std
52{
aa2d5ba2
PE
53 /**
54 * @brief Exception possibly thrown by @c new.
55 *
56 * @c bad_alloc (or classes derived from it) is used to report allocation
669f7a03 57 * errors from the throwing forms of @c new. */
0c952af3
BK
58 class bad_alloc : public exception
59 {
6305f20a 60 public:
f68147f7 61 bad_alloc() throw() { }
949d9ae1 62
e05cd3dd
PC
63 // This declaration is not useless:
64 // http://gcc.gnu.org/onlinedocs/gcc-3.0.2/gcc_6.html#SEC118
d66ae36a 65 virtual ~bad_alloc() throw();
949d9ae1 66
c3f0f556
PC
67 // See comment in eh_exception.cc.
68 virtual const char* what() const throw();
6305f20a
BK
69 };
70
0c952af3 71 struct nothrow_t { };
949d9ae1 72
6305f20a 73 extern const nothrow_t nothrow;
949d9ae1 74
669f7a03
PE
75 /** If you write your own error handler to be called by @c new, it must
76 * be of this type. */
6305f20a 77 typedef void (*new_handler)();
949d9ae1
BK
78
79 /// Takes a replacement handler as the argument, returns the
80 /// previous handler.
984812cd 81 new_handler set_new_handler(new_handler) throw();
6305f20a
BK
82} // namespace std
83
669f7a03
PE
84//@{
85/** These are replaceable signatures:
86 * - normal single new and delete (no arguments, throw @c bad_alloc on error)
87 * - normal array new and delete (same)
88 * - @c nothrow single new and delete (take a @c nothrow argument, return
89 * @c NULL on error)
90 * - @c nothrow array new and delete (same)
91 *
92 * Placement new and delete signatures (take a memory address argument,
93 * does nothing) may not be replaced by a user's program.
94*/
d3a193e3
BK
95void* operator new(std::size_t) throw (std::bad_alloc);
96void* operator new[](std::size_t) throw (std::bad_alloc);
97void operator delete(void*) throw();
98void operator delete[](void*) throw();
99void* operator new(std::size_t, const std::nothrow_t&) throw();
100void* operator new[](std::size_t, const std::nothrow_t&) throw();
101void operator delete(void*, const std::nothrow_t&) throw();
102void operator delete[](void*, const std::nothrow_t&) throw();
6305f20a 103
0c952af3 104// Default placement versions of operator new.
d3a193e3
BK
105inline void* operator new(std::size_t, void* __p) throw() { return __p; }
106inline void* operator new[](std::size_t, void* __p) throw() { return __p; }
51937d2c
BK
107
108// Default placement versions of operator delete.
43be7fe7
MM
109inline void operator delete (void*, void*) throw() { }
110inline void operator delete[](void*, void*) throw() { }
669f7a03 111//@}
6305f20a
BK
112} // extern "C++"
113
723acbd5
MM
114#pragma GCC visibility pop
115
6305f20a 116#endif