diff options
author | Matthijs Kooijman <matthijs@stdin.nl> | 2020-09-17 19:43:09 +0200 |
---|---|---|
committer | Matthijs Kooijman <matthijs@stdin.nl> | 2020-09-17 20:02:05 +0200 |
commit | 6d292502e138b5c73705f0df8095ded3f1df956f (patch) | |
tree | 9f5ce5b42f26358b537dd9807a1c3f8617f5c3d7 /cores/arduino/new | |
parent | 1a885ce890219213ac24c00d5aededa88c122fe1 (diff) |
Use std::size_t in new/delete
The standard dictates that `std::size_t` is used, rather than the plain
`size_t` type.
Even though these types are usually, if not always, exactly the same
type, other code might assume that `std::size_t` is actually used and thus
also available under that name after including `<new>`.
This fixes that by using the right type. One challenge is that it is
usually declared in headers that we do not have available, so this just
defines the `std::size_t` type in the `<new>` header to work around
that.
Diffstat (limited to 'cores/arduino/new')
-rw-r--r-- | cores/arduino/new | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/cores/arduino/new b/cores/arduino/new index fb60927..8cf2103 100644 --- a/cores/arduino/new +++ b/cores/arduino/new @@ -31,23 +31,29 @@ namespace std { typedef void (*new_handler)(); new_handler set_new_handler(new_handler new_p) noexcept; new_handler get_new_handler() noexcept; + + // This is normally declared in various headers that we do not have + // available, so just define it here. We could also use ::size_t + // below, but then anyone including <new> can no longer assume + // std::size_t is available. + using size_t = ::size_t; } // namespace std -[[gnu::weak]] void * operator new(size_t size); -[[gnu::weak]] void * operator new[](size_t size); +[[gnu::weak]] void * operator new(std::size_t size); +[[gnu::weak]] void * operator new[](std::size_t size); -[[gnu::weak]] void * operator new(size_t size, const std::nothrow_t tag) noexcept; -[[gnu::weak]] void * operator new[](size_t size, const std::nothrow_t& tag) noexcept; +[[gnu::weak]] void * operator new(std::size_t size, const std::nothrow_t tag) noexcept; +[[gnu::weak]] void * operator new[](std::size_t size, const std::nothrow_t& tag) noexcept; -void * operator new(size_t size, void *place) noexcept; -void * operator new[](size_t size, void *place) noexcept; +void * operator new(std::size_t size, void *place) noexcept; +void * operator new[](std::size_t size, void *place) noexcept; [[gnu::weak]] void operator delete(void * ptr) noexcept; [[gnu::weak]] void operator delete[](void * ptr) noexcept; #if __cplusplus >= 201402L -[[gnu::weak]] void operator delete(void* ptr, size_t size) noexcept; -[[gnu::weak]] void operator delete[](void * ptr, size_t size) noexcept; +[[gnu::weak]] void operator delete(void* ptr, std::size_t size) noexcept; +[[gnu::weak]] void operator delete[](void * ptr, std::size_t size) noexcept; #endif // __cplusplus >= 201402L [[gnu::weak]] void operator delete(void* ptr, const std::nothrow_t& tag) noexcept; |