blob: 6cc5c23b9e6d0d4ac9c4e2212c981aaf81461df8 [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//
6// This file is distributed under the University of Illinois Open Source
7// License. See LICENSE.TXT for details.
8//
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();
35
36} // std
37
38void* operator new(std::size_t size) throw(std::bad_alloc); // replaceable
39void* operator new(std::size_t size, const std::nothrow_t&) throw(); // replaceable
40void operator delete(void* ptr) throw(); // replaceable
41void operator delete(void* ptr, const std::nothrow_t&) throw(); // replaceable
42
43void* operator new[](std::size_t size) throw(std::bad_alloc); // replaceable
44void* operator new[](std::size_t size, const std::nothrow_t&) throw(); // replaceable
45void operator delete[](void* ptr) throw(); // replaceable
46void operator delete[](void* ptr, const std::nothrow_t&) throw(); // replaceable
47
48void* operator new (std::size_t size, void* ptr) throw();
49void* operator new[](std::size_t size, void* ptr) throw();
50void operator delete (void* ptr, void*) throw();
51void operator delete[](void* ptr, void*) throw();
52
53*/
54
55#include <__config>
56#include <exception>
57#include <cstddef>
58
59#pragma GCC system_header
60
61namespace std // purposefully not using versioning namespace
62{
63
64class _LIBCPP_EXCEPTION_ABI bad_alloc
65 : public exception
66{
67public:
Howard Hinnantd5109772010-08-22 13:53:14 +000068 bad_alloc() throw();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000069 virtual ~bad_alloc() throw();
70 virtual const char* what() const throw();
71};
72
73class _LIBCPP_EXCEPTION_ABI bad_array_new_length
74 : public bad_alloc
75{
76public:
Nick Kledzik804b6e72010-05-14 20:19:37 +000077 bad_array_new_length() throw();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000078 virtual ~bad_array_new_length() throw();
79 virtual const char* what() const throw();
80};
81
Nick Kledzik804b6e72010-05-14 20:19:37 +000082void __throw_bad_alloc(); // not in C++ spec
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000083
Howard Hinnantb9af2ea2010-09-22 18:02:38 +000084struct _LIBCPP_VISIBLE nothrow_t {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000085extern _LIBCPP_VISIBLE const nothrow_t nothrow;
86typedef void (*new_handler)();
87_LIBCPP_VISIBLE new_handler set_new_handler(new_handler) throw();
88
89} // std
90
91_LIBCPP_VISIBLE void* operator new(std::size_t) throw(std::bad_alloc);
92_LIBCPP_VISIBLE void* operator new(std::size_t, const std::nothrow_t&) throw();
93_LIBCPP_VISIBLE void operator delete(void*) throw();
94_LIBCPP_VISIBLE void operator delete(void*, const std::nothrow_t&) throw();
95
96_LIBCPP_VISIBLE void* operator new[](std::size_t) throw(std::bad_alloc);
97_LIBCPP_VISIBLE void* operator new[](std::size_t, const std::nothrow_t&) throw();
98_LIBCPP_VISIBLE void operator delete[](void*) throw();
99_LIBCPP_VISIBLE void operator delete[](void*, const std::nothrow_t&) throw();
100
101_LIBCPP_INLINE_VISIBILITY inline void* operator new (std::size_t, void* __p) throw() {return __p;}
102_LIBCPP_INLINE_VISIBILITY inline void* operator new[](std::size_t, void* __p) throw() {return __p;}
103_LIBCPP_INLINE_VISIBILITY inline void operator delete (void*, void*) throw() {}
104_LIBCPP_INLINE_VISIBILITY inline void operator delete[](void*, void*) throw() {}
105
106#endif // _LIBCPP_NEW