• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
17namespace std
18{
19
20class bad_alloc
21    : public exception
22{
23public:
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
30struct nothrow_t {};
31extern const nothrow_t nothrow;
32typedef void (*new_handler)();
33new_handler set_new_handler(new_handler new_p) noexcept;
34new_handler get_new_handler() noexcept;
35
36}  // std
37
38void* 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
42
43void* 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
47
48void* 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;
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
63namespace std  // purposefully not using versioning namespace
64{
65
66class _LIBCPP_EXCEPTION_ABI bad_alloc
67    : public exception
68{
69public:
70    bad_alloc() _NOEXCEPT;
71    virtual ~bad_alloc() _NOEXCEPT;
72    virtual const char* what() const _NOEXCEPT;
73};
74
75class _LIBCPP_EXCEPTION_ABI bad_array_new_length
76    : public bad_alloc
77{
78public:
79    bad_array_new_length() _NOEXCEPT;
80    virtual ~bad_array_new_length() _NOEXCEPT;
81    virtual const char* what() const _NOEXCEPT;
82};
83
84void __throw_bad_alloc();  // not in C++ spec
85
86struct _LIBCPP_TYPE_VIS nothrow_t {};
87extern _LIBCPP_FUNC_VIS const nothrow_t nothrow;
88typedef 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
118