Add nullptr support to sized delete operators.
This commit is contained in:
parent
41aa41853c
commit
8115f05b26
@ -118,11 +118,17 @@ void operator delete[](void *ptr, const std::nothrow_t &) noexcept
|
|||||||
void
|
void
|
||||||
operator delete(void *ptr, std::size_t size) noexcept
|
operator delete(void *ptr, std::size_t size) noexcept
|
||||||
{
|
{
|
||||||
|
if (unlikely(ptr == nullptr)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
je_sdallocx(ptr, size, /*flags=*/0);
|
je_sdallocx(ptr, size, /*flags=*/0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void operator delete[](void *ptr, std::size_t size) noexcept
|
void operator delete[](void *ptr, std::size_t size) noexcept
|
||||||
{
|
{
|
||||||
|
if (unlikely(ptr == nullptr)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
je_sdallocx(ptr, size, /*flags=*/0);
|
je_sdallocx(ptr, size, /*flags=*/0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,6 +6,16 @@ TEST_BEGIN(test_basic)
|
|||||||
auto foo = new long(4);
|
auto foo = new long(4);
|
||||||
assert_ptr_not_null(foo, "Unexpected new[] failure");
|
assert_ptr_not_null(foo, "Unexpected new[] failure");
|
||||||
delete foo;
|
delete foo;
|
||||||
|
// Test nullptr handling.
|
||||||
|
foo = nullptr;
|
||||||
|
delete foo;
|
||||||
|
|
||||||
|
auto bar = new long;
|
||||||
|
assert_ptr_not_null(bar, "Unexpected new failure");
|
||||||
|
delete bar;
|
||||||
|
// Test nullptr handling.
|
||||||
|
bar = nullptr;
|
||||||
|
delete bar;
|
||||||
}
|
}
|
||||||
TEST_END
|
TEST_END
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user