Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/coreclr/jit/alloc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,27 @@ void* __cdecl operator new[](std::size_t size)
return result;
}

// Also need to override the "nothrow" variants
void* __cdecl operator new(std::size_t size, const std::nothrow_t&) noexcept
{
if (size == 0)
{
size++;
}

return malloc(size);
}

void* __cdecl operator new[](std::size_t size, const std::nothrow_t&) noexcept
{
if (size == 0)
{
size++;
}

return malloc(size);
}
Comment on lines +370 to +388
Copy link

Copilot AI Feb 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The nothrow operator new implementations are missing corresponding nothrow operator delete overloads. According to C++ standard, when providing placement new operators (including nothrow variants), matching placement delete operators should be provided to handle cleanup if construction throws. Add void operator delete(void* ptr, const std::nothrow_t&) noexcept and void operator delete[](void* ptr, const std::nothrow_t&) noexcept that call free(ptr) to match the pattern of the regular delete operators.

Copilot uses AI. Check for mistakes.

void __cdecl operator delete(void* ptr) noexcept
{
free(ptr);
Expand Down
Loading