blob: 68f0274b9c406be07e66f3bf38f8d3ee4cac0810 [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001// -*- C++ -*-
2//===----------------------------- new ------------------------------------===//
3//
Howard Hinnantf5256e12010-05-11 21:36:01 +00004// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00006// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00008//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP_NEW
12#define _LIBCPP_NEW
13
14/*
15 new synopsis
16
17namespace std
18{
19
20class bad_alloc
21 : public exception
22{
23public:
24 bad_alloc() throw();
25 bad_alloc(const bad_alloc&) throw();
26 bad_alloc& operator=(const bad_alloc&) throw();
27 virtual ~bad_alloc() throw();
28 virtual const char* what() const throw();
29};
30
31struct nothrow_t {};
32extern const nothrow_t nothrow;
33typedef void (*new_handler)();
34new_handler set_new_handler(new_handler new_p) throw();
Howard Hinnanta4451512010-12-02 16:45:21 +000035new_handler get_new_handler() throw();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000036
37} // std
38
39void* operator new(std::size_t size) throw(std::bad_alloc); // replaceable
40void* operator new(std::size_t size, const std::nothrow_t&) throw(); // replaceable
41void operator delete(void* ptr) throw(); // replaceable
42void operator delete(void* ptr, const std::nothrow_t&) throw(); // replaceable
43
44void* operator new[](std::size_t size) throw(std::bad_alloc); // replaceable
45void* operator new[](std::size_t size, const std::nothrow_t&) throw(); // replaceable
46void operator delete[](void* ptr) throw(); // replaceable
47void operator delete[](void* ptr, const std::nothrow_t&) throw(); // replaceable
48
49void* operator new (std::size_t size, void* ptr) throw();
50void* operator new[](std::size_t size, void* ptr) throw();
51void operator delete (void* ptr, void*) throw();
52void operator delete[](void* ptr, void*) throw();
53
54*/
55
56#include <__config>
57#include <exception>
58#include <cstddef>
59
60#pragma GCC system_header
61
62namespace std // purposefully not using versioning namespace
63{
64
65class _LIBCPP_EXCEPTION_ABI bad_alloc
66 : public exception
67{
68public:
Howard Hinnantd5109772010-08-22 13:53:14 +000069 bad_alloc() throw();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000070 virtual ~bad_alloc() throw();
71 virtual const char* what() const throw();
72};
73
74class _LIBCPP_EXCEPTION_ABI bad_array_new_length
75 : public bad_alloc
76{
77public:
Nick Kledzik804b6e72010-05-14 20:19:37 +000078 bad_array_new_length() throw();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000079 virtual ~bad_array_new_length() throw();
80 virtual const char* what() const throw();
81};
82
Nick Kledzik804b6e72010-05-14 20:19:37 +000083void __throw_bad_alloc(); // not in C++ spec
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000084
Howard Hinnantb9af2ea2010-09-22 18:02:38 +000085struct _LIBCPP_VISIBLE nothrow_t {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000086extern _LIBCPP_VISIBLE const nothrow_t nothrow;
87typedef void (*new_handler)();
88_LIBCPP_VISIBLE new_handler set_new_handler(new_handler) throw();
Howard Hinnanta4451512010-12-02 16:45:21 +000089_LIBCPP_VISIBLE new_handler get_new_handler() throw();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000090
91} // std
92
93_LIBCPP_VISIBLE void* operator new(std::size_t) throw(std::bad_alloc);
94_LIBCPP_VISIBLE void* operator new(std::size_t, const std::nothrow_t&) throw();
95_LIBCPP_VISIBLE void operator delete(void*) throw();
96_LIBCPP_VISIBLE void operator delete(void*, const std::nothrow_t&) throw();
97
98_LIBCPP_VISIBLE void* operator new[](std::size_t) throw(std::bad_alloc);
99_LIBCPP_VISIBLE void* operator new[](std::size_t, const std::nothrow_t&) throw();
100_LIBCPP_VISIBLE void operator delete[](void*) throw();
101_LIBCPP_VISIBLE void operator delete[](void*, const std::nothrow_t&) throw();
102
103_LIBCPP_INLINE_VISIBILITY inline void* operator new (std::size_t, void* __p) throw() {return __p;}
104_LIBCPP_INLINE_VISIBILITY inline void* operator new[](std::size_t, void* __p) throw() {return __p;}
105_LIBCPP_INLINE_VISIBILITY inline void operator delete (void*, void*) throw() {}
106_LIBCPP_INLINE_VISIBILITY inline void operator delete[](void*, void*) throw() {}
107
108#endif // _LIBCPP_NEW