]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - contrib/libc++/include/new
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / contrib / libc++ / include / new
1 // -*- C++ -*-
2 //===----------------------------- new ------------------------------------===//
3 //
4 //                     The LLVM Compiler Infrastructure
5 //
6 // This file is dual licensed under the MIT and the University of Illinois Open
7 // Source Licenses. See LICENSE.TXT for details.
8 //
9 //===----------------------------------------------------------------------===//
10
11 #ifndef _LIBCPP_NEW
12 #define _LIBCPP_NEW
13
14 /*
15     new synopsis
16
17 namespace std
18 {
19
20 class bad_alloc
21     : public exception
22 {
23 public:
24     bad_alloc() noexcept;
25     bad_alloc(const bad_alloc&) noexcept;
26     bad_alloc& operator=(const bad_alloc&) noexcept;
27     virtual const char* what() const noexcept;
28 };
29
30 struct nothrow_t {};
31 extern const nothrow_t nothrow;
32 typedef void (*new_handler)();
33 new_handler set_new_handler(new_handler new_p) noexcept;
34 new_handler get_new_handler() noexcept;
35
36 }  // std
37
38 void* operator new(std::size_t size);                                   // replaceable
39 void* operator new(std::size_t size, const std::nothrow_t&) noexcept;   // replaceable
40 void  operator delete(void* ptr) noexcept;                              // replaceable
41 void  operator delete(void* ptr, const std::nothrow_t&) noexcept;       // replaceable
42
43 void* operator new[](std::size_t size);                                 // replaceable
44 void* operator new[](std::size_t size, const std::nothrow_t&) noexcept; // replaceable
45 void  operator delete[](void* ptr) noexcept;                            // replaceable
46 void  operator delete[](void* ptr, const std::nothrow_t&) noexcept;     // replaceable
47
48 void* operator new  (std::size_t size, void* ptr) noexcept;
49 void* operator new[](std::size_t size, void* ptr) noexcept;
50 void  operator delete  (void* ptr, void*) noexcept;
51 void  operator delete[](void* ptr, void*) noexcept;
52
53 */
54
55 #include <__config>
56 #include <exception>
57 #include <cstddef>
58
59 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
60 #pragma GCC system_header
61 #endif
62
63 namespace std  // purposefully not using versioning namespace
64 {
65
66 class _LIBCPP_EXCEPTION_ABI bad_alloc
67     : public exception
68 {
69 public:
70     bad_alloc() _NOEXCEPT;
71     virtual ~bad_alloc() _NOEXCEPT;
72     virtual const char* what() const _NOEXCEPT;
73 };
74
75 class _LIBCPP_EXCEPTION_ABI bad_array_new_length
76     : public bad_alloc
77 {
78 public:
79     bad_array_new_length() _NOEXCEPT;
80     virtual ~bad_array_new_length() _NOEXCEPT;
81     virtual const char* what() const _NOEXCEPT;
82 };
83
84 void __throw_bad_alloc();  // not in C++ spec
85
86 struct _LIBCPP_TYPE_VIS nothrow_t {};
87 extern _LIBCPP_FUNC_VIS const nothrow_t nothrow;
88 typedef void (*new_handler)();
89 _LIBCPP_FUNC_VIS new_handler set_new_handler(new_handler) _NOEXCEPT;
90 _LIBCPP_FUNC_VIS new_handler get_new_handler() _NOEXCEPT;
91
92 }  // std
93
94 _LIBCPP_FUNC_VIS void* operator new(std::size_t __sz)
95 #if !__has_feature(cxx_noexcept)
96     throw(std::bad_alloc)
97 #endif
98 ;
99 _LIBCPP_FUNC_VIS void* operator new(std::size_t __sz, const std::nothrow_t&) _NOEXCEPT _NOALIAS;
100 _LIBCPP_FUNC_VIS void  operator delete(void* __p) _NOEXCEPT;
101 _LIBCPP_FUNC_VIS void  operator delete(void* __p, const std::nothrow_t&) _NOEXCEPT;
102
103 _LIBCPP_FUNC_VIS void* operator new[](std::size_t __sz)
104 #if !__has_feature(cxx_noexcept)
105     throw(std::bad_alloc)
106 #endif
107 ;
108 _LIBCPP_FUNC_VIS void* operator new[](std::size_t __sz, const std::nothrow_t&) _NOEXCEPT _NOALIAS;
109 _LIBCPP_FUNC_VIS void  operator delete[](void* __p) _NOEXCEPT;
110 _LIBCPP_FUNC_VIS void  operator delete[](void* __p, const std::nothrow_t&) _NOEXCEPT;
111
112 _LIBCPP_INLINE_VISIBILITY inline void* operator new  (std::size_t, void* __p) _NOEXCEPT {return __p;}
113 _LIBCPP_INLINE_VISIBILITY inline void* operator new[](std::size_t, void* __p) _NOEXCEPT {return __p;}
114 _LIBCPP_INLINE_VISIBILITY inline void  operator delete  (void*, void*) _NOEXCEPT {}
115 _LIBCPP_INLINE_VISIBILITY inline void  operator delete[](void*, void*) _NOEXCEPT {}
116
117 #endif  // _LIBCPP_NEW