mirror of
https://github.com/Dasharo/zephyr.git
synced 2026-03-06 14:57:20 -08:00
cpp: new: Add no-throwing implementation of new operator
C++ subsystem defines exception throwing operator new. Though the implementation never throws an exception. If used by an application it should verify if requested memory was allocated. This is against C++ standard. If an application does not support exceptions or does not want to call throwing new operator, it should use a specialization of a new operator that makes sure it never throws bad_alloc exception. The cpp subsystem does not provide this specialization. The commit adds missing operator new specializations. Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
This commit is contained in:
@@ -22,6 +22,16 @@ void* operator new[](size_t size)
|
||||
return malloc(size);
|
||||
}
|
||||
|
||||
void* operator new(std::size_t size, const std::nothrow_t& tag) NOEXCEPT
|
||||
{
|
||||
return malloc(size);
|
||||
}
|
||||
|
||||
void* operator new[](std::size_t size, const std::nothrow_t& tag) NOEXCEPT
|
||||
{
|
||||
return malloc(size);
|
||||
}
|
||||
|
||||
void operator delete(void* ptr) NOEXCEPT
|
||||
{
|
||||
free(ptr);
|
||||
|
||||
Reference in New Issue
Block a user