diff --git a/libc/bionic/new.cpp b/libc/bionic/new.cpp index c9ce163f5..5a6acc0e4 100644 --- a/libc/bionic/new.cpp +++ b/libc/bionic/new.cpp @@ -16,13 +16,14 @@ #include -#include #include #include __attribute__((weak)) const std::nothrow_t std::nothrow = {}; +// We can't throw in bionic, so we go straight to the equivalent of +// std::terminate for these two instead. void* operator new(std::size_t size) { void* p = malloc(size); if (p == nullptr) { @@ -30,7 +31,6 @@ void* operator new(std::size_t size) { } return p; } - void* operator new[](std::size_t size) { void* p = malloc(size); if (p == nullptr) { @@ -39,26 +39,21 @@ void* operator new[](std::size_t size) { return p; } -void operator delete(void* ptr) throw() { - free(ptr); -} - -void operator delete[](void* ptr) throw() { - free(ptr); -} - +// These two are the "nothrow" variants, so we just return nullptr on failure. void* operator new(std::size_t size, const std::nothrow_t&) { return malloc(size); } - void* operator new[](std::size_t size, const std::nothrow_t&) { return malloc(size); } -void operator delete(void* ptr, const std::nothrow_t&) throw() { - free(ptr); -} +// free() can't throw anyway (except on heap corruption, which is always fatal), +// so there's no difference between the regular and "nothrow" variants here. +void operator delete(void* p) noexcept { free(p); } +void operator delete[](void* p) noexcept { free(p); } +void operator delete(void* p, const std::nothrow_t&) noexcept { free(p); } +void operator delete[](void* p, const std::nothrow_t&) noexcept { free(p); } -void operator delete[](void* ptr, const std::nothrow_t&) throw() { - free(ptr); -} +// TODO: these can use free_sized() once we have it (http://b/284321795). +void operator delete(void* p, std::size_t) noexcept { free(p); } +void operator delete[](void* p, std::size_t) noexcept { free(p); }