blob: fac9f853009398c21ec1fb8c57eb54069f95b0ec [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:
Howard Hinnanted569212011-05-26 18:23:59 +000024 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;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000028};
29
30struct nothrow_t {};
31extern const nothrow_t nothrow;
32typedef void (*new_handler)();
Howard Hinnanted569212011-05-26 18:23:59 +000033new_handler set_new_handler(new_handler new_p) noexcept;
34new_handler get_new_handler() noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000035
36} // std
37
Howard Hinnanted569212011-05-26 18:23:59 +000038void* operator new(std::size_t size); // replaceable
39void* operator new(std::size_t size, const std::nothrow_t&) noexcept; // replaceable
40void operator delete(void* ptr) noexcept; // replaceable
41void operator delete(void* ptr, const std::nothrow_t&) noexcept; // replaceable
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000042
Howard Hinnanted569212011-05-26 18:23:59 +000043void* operator new[](std::size_t size); // replaceable
44void* operator new[](std::size_t size, const std::nothrow_t&) noexcept; // replaceable
45void operator delete[](void* ptr) noexcept; // replaceable
46void operator delete[](void* ptr, const std::nothrow_t&) noexcept; // replaceable
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000047
Howard Hinnanted569212011-05-26 18:23:59 +000048void* operator new (std::size_t size, void* ptr) noexcept;
49void* operator new[](std::size_t size, void* ptr) noexcept;
50void operator delete (void* ptr, void*) noexcept;
51void operator delete[](void* ptr, void*) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000052
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 Hinnanted569212011-05-26 18:23:59 +000068 bad_alloc() _NOEXCEPT;
69 virtual ~bad_alloc() _NOEXCEPT;
70 virtual const char* what() const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000071};
72
73class _LIBCPP_EXCEPTION_ABI bad_array_new_length
74 : public bad_alloc
75{
76public:
Howard Hinnanted569212011-05-26 18:23:59 +000077 bad_array_new_length() _NOEXCEPT;
78 virtual ~bad_array_new_length() _NOEXCEPT;
79 virtual const char* what() const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000080};
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)();
Howard Hinnanted569212011-05-26 18:23:59 +000087_LIBCPP_VISIBLE new_handler set_new_handler(new_handler) _NOEXCEPT;
88_LIBCPP_VISIBLE new_handler get_new_handler() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000089
90} // std
91
Howard Hinnanted569212011-05-26 18:23:59 +000092_LIBCPP_VISIBLE void* operator new(std::size_t)
93#if !__has_feature(cxx_noexcept)
94 throw(std::bad_alloc)
95#endif
96;
97_LIBCPP_VISIBLE void* operator new(std::size_t, const std::nothrow_t&) _NOEXCEPT;
98_LIBCPP_VISIBLE void operator delete(void*) _NOEXCEPT;
99_LIBCPP_VISIBLE void operator delete(void*, const std::nothrow_t&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000100
Howard Hinnanted569212011-05-26 18:23:59 +0000101_LIBCPP_VISIBLE void* operator new[](std::size_t)
102#if !__has_feature(cxx_noexcept)
103 throw(std::bad_alloc)
104#endif
105;
106_LIBCPP_VISIBLE void* operator new[](std::size_t, const std::nothrow_t&) _NOEXCEPT;
107_LIBCPP_VISIBLE void operator delete[](void*) _NOEXCEPT;
108_LIBCPP_VISIBLE void operator delete[](void*, const std::nothrow_t&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000109
Howard Hinnanted569212011-05-26 18:23:59 +0000110_LIBCPP_INLINE_VISIBILITY inline void* operator new (std::size_t, void* __p) _NOEXCEPT {return __p;}
111_LIBCPP_INLINE_VISIBILITY inline void* operator new[](std::size_t, void* __p) _NOEXCEPT {return __p;}
112_LIBCPP_INLINE_VISIBILITY inline void operator delete (void*, void*) _NOEXCEPT {}
113_LIBCPP_INLINE_VISIBILITY inline void operator delete[](void*, void*) _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000114
115#endif // _LIBCPP_NEW