197403Sobrien// The -*- C++ -*- dynamic memory management header. 297403Sobrien 3169691Skan// Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 4169691Skan// 2003, 2004, 2005, 2006, 2007 597403Sobrien// Free Software Foundation 697403Sobrien 7132720Skan// This file is part of GCC. 897403Sobrien// 9132720Skan// GCC is free software; you can redistribute it and/or modify 1097403Sobrien// it under the terms of the GNU General Public License as published by 1197403Sobrien// the Free Software Foundation; either version 2, or (at your option) 1297403Sobrien// any later version. 1397403Sobrien// 14132720Skan// GCC is distributed in the hope that it will be useful, 1597403Sobrien// but WITHOUT ANY WARRANTY; without even the implied warranty of 1697403Sobrien// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1797403Sobrien// GNU General Public License for more details. 1897403Sobrien// 1997403Sobrien// You should have received a copy of the GNU General Public License 20132720Skan// along with GCC; see the file COPYING. If not, write to 21169691Skan// the Free Software Foundation, 51 Franklin Street, Fifth Floor, 22169691Skan// Boston, MA 02110-1301, USA. 2397403Sobrien 2497403Sobrien// As a special exception, you may use this file as part of a free software 2597403Sobrien// library without restriction. Specifically, if other files instantiate 2697403Sobrien// templates or use macros or inline functions from this file, or you compile 2797403Sobrien// this file and link it with other files to produce an executable, this 2897403Sobrien// file does not by itself cause the resulting executable to be covered by 2997403Sobrien// the GNU General Public License. This exception does not however 3097403Sobrien// invalidate any other reasons why the executable file might be covered by 3197403Sobrien// the GNU General Public License. 3297403Sobrien 3397403Sobrien/** @file new 34169691Skan * This is a Standard C++ Library header. 35169691Skan * 3697403Sobrien * The header @c new defines several functions to manage dynamic memory and 3797403Sobrien * handling memory allocation errors; see 3897403Sobrien * http://gcc.gnu.org/onlinedocs/libstdc++/18_support/howto.html#4 for more. 3997403Sobrien */ 4097403Sobrien 41132720Skan#ifndef _NEW 42132720Skan#define _NEW 4397403Sobrien 4497403Sobrien#include <cstddef> 4597403Sobrien#include <exception> 4697403Sobrien 47169691Skan#pragma GCC visibility push(default) 48169691Skan 4997403Sobrienextern "C++" { 5097403Sobrien 5197403Sobriennamespace std 5297403Sobrien{ 53117397Skan /** 54117397Skan * @brief Exception possibly thrown by @c new. 55117397Skan * 56117397Skan * @c bad_alloc (or classes derived from it) is used to report allocation 5797403Sobrien * errors from the throwing forms of @c new. */ 5897403Sobrien class bad_alloc : public exception 5997403Sobrien { 6097403Sobrien public: 6197403Sobrien bad_alloc() throw() { } 62171827Skan 6397403Sobrien // This declaration is not useless: 6497403Sobrien // http://gcc.gnu.org/onlinedocs/gcc-3.0.2/gcc_6.html#SEC118 6597403Sobrien virtual ~bad_alloc() throw(); 66171827Skan 67169691Skan // See comment in eh_exception.cc. 68169691Skan virtual const char* what() const throw(); 6997403Sobrien }; 7097403Sobrien 7197403Sobrien struct nothrow_t { }; 72171827Skan 7397403Sobrien extern const nothrow_t nothrow; 74171827Skan 7597403Sobrien /** If you write your own error handler to be called by @c new, it must 7697403Sobrien * be of this type. */ 7797403Sobrien typedef void (*new_handler)(); 78171827Skan 79171827Skan /// Takes a replacement handler as the argument, returns the 80171827Skan /// previous handler. 81102782Skan new_handler set_new_handler(new_handler) throw(); 8297403Sobrien} // namespace std 8397403Sobrien 8497403Sobrien//@{ 8597403Sobrien/** These are replaceable signatures: 8697403Sobrien * - normal single new and delete (no arguments, throw @c bad_alloc on error) 8797403Sobrien * - normal array new and delete (same) 8897403Sobrien * - @c nothrow single new and delete (take a @c nothrow argument, return 8997403Sobrien * @c NULL on error) 9097403Sobrien * - @c nothrow array new and delete (same) 9197403Sobrien * 9297403Sobrien * Placement new and delete signatures (take a memory address argument, 9397403Sobrien * does nothing) may not be replaced by a user's program. 9497403Sobrien*/ 9597403Sobrienvoid* operator new(std::size_t) throw (std::bad_alloc); 9697403Sobrienvoid* operator new[](std::size_t) throw (std::bad_alloc); 9797403Sobrienvoid operator delete(void*) throw(); 9897403Sobrienvoid operator delete[](void*) throw(); 9997403Sobrienvoid* operator new(std::size_t, const std::nothrow_t&) throw(); 10097403Sobrienvoid* operator new[](std::size_t, const std::nothrow_t&) throw(); 10197403Sobrienvoid operator delete(void*, const std::nothrow_t&) throw(); 10297403Sobrienvoid operator delete[](void*, const std::nothrow_t&) throw(); 10397403Sobrien 10497403Sobrien// Default placement versions of operator new. 10597403Sobrieninline void* operator new(std::size_t, void* __p) throw() { return __p; } 10697403Sobrieninline void* operator new[](std::size_t, void* __p) throw() { return __p; } 107102782Skan 108102782Skan// Default placement versions of operator delete. 109132720Skaninline void operator delete (void*, void*) throw() { } 110132720Skaninline void operator delete[](void*, void*) throw() { } 11197403Sobrien//@} 11297403Sobrien} // extern "C++" 11397403Sobrien 114169691Skan#pragma GCC visibility pop 115169691Skan 11697403Sobrien#endif 117