xref: /haiku/headers/private/kernel/util/kernel_cpp.h (revision 220c5364ab445eb20376f964ade2f7d3a09e163a)
1 #ifndef KERNEL_CPP_H
2 #define KERNEL_CPP_H
3 /* cpp - C++ in the kernel
4 **
5 ** Initial version by Axel Dörfler, axeld@pinc-software.de
6 ** This file may be used under the terms of the OpenBeOS License.
7 */
8 
9 #ifdef __cplusplus
10 
11 #include <new>
12 #include <stdlib.h>
13 
14 #if _KERNEL_MODE || _LOADER_MODE
15 
16 using namespace std;
17 extern const nothrow_t std::nothrow;
18 
19 // We need new() versions we can use when also linking against libgcc.
20 // std::nothrow can't be used since it's defined in both libgcc and
21 // kernel_cpp.cpp.
22 typedef struct {} mynothrow_t;
23 extern const mynothrow_t mynothrow;
24 
25 #ifndef __clang__
26 extern void* operator new(size_t size) throw (std::bad_alloc);
27 extern void* operator new[](size_t size) throw (std::bad_alloc);
28 extern void* operator new(size_t size, const std::nothrow_t &) throw ();
29 extern void* operator new[](size_t size, const std::nothrow_t &) throw ();
30 extern void* operator new(size_t size, const mynothrow_t &) throw ();
31 extern void* operator new[](size_t size, const mynothrow_t &) throw ();
32 extern void operator delete(void *ptr) throw ();
33 extern void operator delete[](void *ptr) throw ();
34 #endif
35 
36 #if __cplusplus >= 201402L
37 
38 inline void
39 operator delete(void *ptr, size_t size) throw ()
40 {
41 	free(ptr);
42 }
43 
44 #endif // __cplusplus >= 201402L
45 
46 #endif	// #if _KERNEL_MODE
47 
48 #endif	// __cplusplus
49 
50 #endif	/* KERNEL_CPP_H */
51