xref: /dflybsd-src/contrib/gcc-4.7/libstdc++-v3/libsupc++/new (revision 04febcfb30580676d3e95f58a16c5137ee478b32)
1*e4b17023SJohn Marino// The -*- C++ -*- dynamic memory management header.
2*e4b17023SJohn Marino
3*e4b17023SJohn Marino// Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
4*e4b17023SJohn Marino// 2003, 2004, 2005, 2006, 2007, 2009, 2010, 2011
5*e4b17023SJohn Marino// Free Software Foundation
6*e4b17023SJohn Marino
7*e4b17023SJohn Marino// This file is part of GCC.
8*e4b17023SJohn Marino//
9*e4b17023SJohn Marino// GCC is free software; you can redistribute it and/or modify
10*e4b17023SJohn Marino// it under the terms of the GNU General Public License as published by
11*e4b17023SJohn Marino// the Free Software Foundation; either version 3, or (at your option)
12*e4b17023SJohn Marino// any later version.
13*e4b17023SJohn Marino//
14*e4b17023SJohn Marino// GCC is distributed in the hope that it will be useful,
15*e4b17023SJohn Marino// but WITHOUT ANY WARRANTY; without even the implied warranty of
16*e4b17023SJohn Marino// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17*e4b17023SJohn Marino// GNU General Public License for more details.
18*e4b17023SJohn Marino//
19*e4b17023SJohn Marino// Under Section 7 of GPL version 3, you are granted additional
20*e4b17023SJohn Marino// permissions described in the GCC Runtime Library Exception, version
21*e4b17023SJohn Marino// 3.1, as published by the Free Software Foundation.
22*e4b17023SJohn Marino
23*e4b17023SJohn Marino// You should have received a copy of the GNU General Public License and
24*e4b17023SJohn Marino// a copy of the GCC Runtime Library Exception along with this program;
25*e4b17023SJohn Marino// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
26*e4b17023SJohn Marino// <http://www.gnu.org/licenses/>.
27*e4b17023SJohn Marino
28*e4b17023SJohn Marino/** @file new
29*e4b17023SJohn Marino *  This is a Standard C++ Library header.
30*e4b17023SJohn Marino *
31*e4b17023SJohn Marino *  The header @c new defines several functions to manage dynamic memory and
32*e4b17023SJohn Marino *  handling memory allocation errors; see
33*e4b17023SJohn Marino *  http://gcc.gnu.org/onlinedocs/libstdc++/18_support/howto.html#4 for more.
34*e4b17023SJohn Marino */
35*e4b17023SJohn Marino
36*e4b17023SJohn Marino#ifndef _NEW
37*e4b17023SJohn Marino#define _NEW
38*e4b17023SJohn Marino
39*e4b17023SJohn Marino#pragma GCC system_header
40*e4b17023SJohn Marino
41*e4b17023SJohn Marino#include <bits/c++config.h>
42*e4b17023SJohn Marino#include <exception>
43*e4b17023SJohn Marino
44*e4b17023SJohn Marino#pragma GCC visibility push(default)
45*e4b17023SJohn Marino
46*e4b17023SJohn Marinoextern "C++" {
47*e4b17023SJohn Marino
48*e4b17023SJohn Marinonamespace std
49*e4b17023SJohn Marino{
50*e4b17023SJohn Marino  /**
51*e4b17023SJohn Marino   *  @brief  Exception possibly thrown by @c new.
52*e4b17023SJohn Marino   *  @ingroup exceptions
53*e4b17023SJohn Marino   *
54*e4b17023SJohn Marino   *  @c bad_alloc (or classes derived from it) is used to report allocation
55*e4b17023SJohn Marino   *  errors from the throwing forms of @c new.  */
56*e4b17023SJohn Marino  class bad_alloc : public exception
57*e4b17023SJohn Marino  {
58*e4b17023SJohn Marino  public:
59*e4b17023SJohn Marino    bad_alloc() throw() { }
60*e4b17023SJohn Marino
61*e4b17023SJohn Marino    // This declaration is not useless:
62*e4b17023SJohn Marino    // http://gcc.gnu.org/onlinedocs/gcc-3.0.2/gcc_6.html#SEC118
63*e4b17023SJohn Marino    virtual ~bad_alloc() throw();
64*e4b17023SJohn Marino
65*e4b17023SJohn Marino    // See comment in eh_exception.cc.
66*e4b17023SJohn Marino    virtual const char* what() const throw();
67*e4b17023SJohn Marino  };
68*e4b17023SJohn Marino
69*e4b17023SJohn Marino  struct nothrow_t { };
70*e4b17023SJohn Marino
71*e4b17023SJohn Marino  extern const nothrow_t nothrow;
72*e4b17023SJohn Marino
73*e4b17023SJohn Marino  /** If you write your own error handler to be called by @c new, it must
74*e4b17023SJohn Marino   *  be of this type.  */
75*e4b17023SJohn Marino  typedef void (*new_handler)();
76*e4b17023SJohn Marino
77*e4b17023SJohn Marino  /// Takes a replacement handler as the argument, returns the
78*e4b17023SJohn Marino  /// previous handler.
79*e4b17023SJohn Marino  new_handler set_new_handler(new_handler) throw();
80*e4b17023SJohn Marino} // namespace std
81*e4b17023SJohn Marino
82*e4b17023SJohn Marino//@{
83*e4b17023SJohn Marino/** These are replaceable signatures:
84*e4b17023SJohn Marino *  - normal single new and delete (no arguments, throw @c bad_alloc on error)
85*e4b17023SJohn Marino *  - normal array new and delete (same)
86*e4b17023SJohn Marino *  - @c nothrow single new and delete (take a @c nothrow argument, return
87*e4b17023SJohn Marino *    @c NULL on error)
88*e4b17023SJohn Marino *  - @c nothrow array new and delete (same)
89*e4b17023SJohn Marino *
90*e4b17023SJohn Marino *  Placement new and delete signatures (take a memory address argument,
91*e4b17023SJohn Marino *  does nothing) may not be replaced by a user's program.
92*e4b17023SJohn Marino*/
93*e4b17023SJohn Marinovoid* operator new(std::size_t) _GLIBCXX_THROW (std::bad_alloc)
94*e4b17023SJohn Marino  __attribute__((__externally_visible__));
95*e4b17023SJohn Marinovoid* operator new[](std::size_t) _GLIBCXX_THROW (std::bad_alloc)
96*e4b17023SJohn Marino  __attribute__((__externally_visible__));
97*e4b17023SJohn Marinovoid operator delete(void*) _GLIBCXX_USE_NOEXCEPT
98*e4b17023SJohn Marino  __attribute__((__externally_visible__));
99*e4b17023SJohn Marinovoid operator delete[](void*) _GLIBCXX_USE_NOEXCEPT
100*e4b17023SJohn Marino  __attribute__((__externally_visible__));
101*e4b17023SJohn Marinovoid* operator new(std::size_t, const std::nothrow_t&) _GLIBCXX_USE_NOEXCEPT
102*e4b17023SJohn Marino  __attribute__((__externally_visible__));
103*e4b17023SJohn Marinovoid* operator new[](std::size_t, const std::nothrow_t&) _GLIBCXX_USE_NOEXCEPT
104*e4b17023SJohn Marino  __attribute__((__externally_visible__));
105*e4b17023SJohn Marinovoid operator delete(void*, const std::nothrow_t&) _GLIBCXX_USE_NOEXCEPT
106*e4b17023SJohn Marino  __attribute__((__externally_visible__));
107*e4b17023SJohn Marinovoid operator delete[](void*, const std::nothrow_t&) _GLIBCXX_USE_NOEXCEPT
108*e4b17023SJohn Marino  __attribute__((__externally_visible__));
109*e4b17023SJohn Marino
110*e4b17023SJohn Marino// Default placement versions of operator new.
111*e4b17023SJohn Marinoinline void* operator new(std::size_t, void* __p) _GLIBCXX_USE_NOEXCEPT
112*e4b17023SJohn Marino{ return __p; }
113*e4b17023SJohn Marinoinline void* operator new[](std::size_t, void* __p) _GLIBCXX_USE_NOEXCEPT
114*e4b17023SJohn Marino{ return __p; }
115*e4b17023SJohn Marino
116*e4b17023SJohn Marino// Default placement versions of operator delete.
117*e4b17023SJohn Marinoinline void operator delete  (void*, void*) _GLIBCXX_USE_NOEXCEPT { }
118*e4b17023SJohn Marinoinline void operator delete[](void*, void*) _GLIBCXX_USE_NOEXCEPT { }
119*e4b17023SJohn Marino//@}
120*e4b17023SJohn Marino} // extern "C++"
121*e4b17023SJohn Marino
122*e4b17023SJohn Marino#pragma GCC visibility pop
123*e4b17023SJohn Marino
124*e4b17023SJohn Marino#endif
125