Skip to content

Commit 7d002f5

Browse files
committed
Missed a C++ exceptions globally disabled fix.
1 parent c94e8f8 commit 7d002f5

1 file changed

Lines changed: 34 additions & 7 deletions

File tree

include/quickcpplib/memory_resource.hpp

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ QUICKCPPLIB_NAMESPACE_END
5252
#include <cstddef>
5353
#include <memory>
5454

55+
#include "cpp_feature.h"
56+
5557
QUICKCPPLIB_NAMESPACE_BEGIN
5658

5759
namespace pmr
@@ -71,11 +73,23 @@ namespace pmr
7173
memory_resource &operator=(const memory_resource &) = default;
7274
virtual ~memory_resource() {}
7375

74-
QUICKCPPLIB_NODISCARD void *allocate(size_t bytes, size_t alignment = alignof(std::max_align_t)) { return do_allocate(bytes, alignment); }
75-
void deallocate(void *p, size_t bytes, size_t alignment = alignof(std::max_align_t)) { return do_deallocate(p, bytes, alignment); }
76+
QUICKCPPLIB_NODISCARD void *allocate(size_t bytes, size_t alignment = alignof(std::max_align_t))
77+
{
78+
return do_allocate(bytes, alignment);
79+
}
80+
void deallocate(void *p, size_t bytes, size_t alignment = alignof(std::max_align_t))
81+
{
82+
return do_deallocate(p, bytes, alignment);
83+
}
7684
};
77-
inline bool operator==(const memory_resource &a, const memory_resource &b) noexcept { return a.do_is_equal(b); }
78-
inline bool operator!=(const memory_resource &a, const memory_resource &b) noexcept { return !a.do_is_equal(b); }
85+
inline bool operator==(const memory_resource &a, const memory_resource &b) noexcept
86+
{
87+
return a.do_is_equal(b);
88+
}
89+
inline bool operator!=(const memory_resource &a, const memory_resource &b) noexcept
90+
{
91+
return !a.do_is_equal(b);
92+
}
7993

8094
//! A just barely good enough C++ 14 emulation of monotonic_buffer_resource
8195
class monotonic_buffer_resource : public memory_resource
@@ -86,14 +100,22 @@ namespace pmr
86100
{
87101
if(_ptr >= _end)
88102
{
103+
#ifdef __cpp_exceptions
89104
throw std::bad_alloc();
105+
#else
106+
abort();
107+
#endif
90108
}
91109
_ptr = (char *) (((uintptr_t) _ptr + alignment - 1) & ~(alignment - 1));
92110
void *ret = (void *) _ptr;
93111
_ptr += bytes;
94112
if(_ptr > _end)
95113
{
114+
#ifdef __cpp_exceptions
96115
throw std::bad_alloc();
116+
#else
117+
abort();
118+
#endif
97119
}
98120
return ret;
99121
}
@@ -143,16 +165,21 @@ namespace pmr
143165

144166
memory_resource *resource() const { return _r; }
145167

146-
QUICKCPPLIB_NODISCARD T *allocate(size_t n) { return static_cast<T *>(resource()->allocate(n * sizeof(T), alignof(T))); }
168+
QUICKCPPLIB_NODISCARD T *allocate(size_t n)
169+
{
170+
return static_cast<T *>(resource()->allocate(n * sizeof(T), alignof(T)));
171+
}
147172
void deallocate(T *p, size_t n) { resource()->deallocate(p, n * sizeof(T), alignof(T)); }
148173
template <class U, class... Args> void construct(U *p, Args &&...args) { new(p) U(static_cast<Args &&>(args)...); }
149174
template <class U> void destroy(U *p) { p->~U(); }
150175
};
151-
template <class T1, class T2> inline bool operator==(const polymorphic_allocator<T1> &a, const polymorphic_allocator<T2> &b) noexcept
176+
template <class T1, class T2>
177+
inline bool operator==(const polymorphic_allocator<T1> &a, const polymorphic_allocator<T2> &b) noexcept
152178
{
153179
return *a.resource() == *b.resource();
154180
}
155-
template <class T1, class T2> inline bool operator!=(const polymorphic_allocator<T1> &a, const polymorphic_allocator<T2> &b) noexcept
181+
template <class T1, class T2>
182+
inline bool operator!=(const polymorphic_allocator<T1> &a, const polymorphic_allocator<T2> &b) noexcept
156183
{
157184
return *a.resource() != *b.resource();
158185
}

0 commit comments

Comments
 (0)