[libcxx-commits] [libcxx] [libc++] Fix missing 'get_new_handler()' for Windows builds (PR #150182)

via libcxx-commits libcxx-commits at lists.llvm.org
Wed Jul 23 00:42:44 PDT 2025


https://github.com/siradam7th created https://github.com/llvm/llvm-project/pull/150182

The following PR fixes the missing `get_new_handler()` function for Windows by using the same implementation as other platforms since `<new.h>` in the UCRT is missing this function and only defines `set_new_handler()` so it is best if all of them are defined by libc++.

Fixes: 
- https://github.com/llvm/llvm-project/issues/64813

Related PR:
> TL;DR: Originally part of it, then moved into its own PR.
- https://github.com/llvm/llvm-project/pull/148992/

>From e04029eacf02427d0bb11703a0565fdca74b0cf1 Mon Sep 17 00:00:00 2001
From: siradam7th <siradam7th at users.noreply.github.com>
Date: Wed, 23 Jul 2025 08:28:44 +0100
Subject: [PATCH] fix missing 'get_new_handler()' for Windows builds

---
 libcxx/include/__new/new_handler.h | 4 ----
 libcxx/src/new_handler.cpp         | 4 +---
 2 files changed, 1 insertion(+), 7 deletions(-)

diff --git a/libcxx/include/__new/new_handler.h b/libcxx/include/__new/new_handler.h
index 05f4e846c3ef9..8f93578da9f9c 100644
--- a/libcxx/include/__new/new_handler.h
+++ b/libcxx/include/__new/new_handler.h
@@ -15,14 +15,10 @@
 #  pragma GCC system_header
 #endif
 
-#if defined(_LIBCPP_ABI_VCRUNTIME)
-#  include <new.h>
-#else
 _LIBCPP_BEGIN_UNVERSIONED_NAMESPACE_STD
 typedef void (*new_handler)();
 _LIBCPP_EXPORTED_FROM_ABI new_handler set_new_handler(new_handler) _NOEXCEPT;
 _LIBCPP_EXPORTED_FROM_ABI new_handler get_new_handler() _NOEXCEPT;
 _LIBCPP_END_UNVERSIONED_NAMESPACE_STD
-#endif // _LIBCPP_ABI_VCRUNTIME
 
 #endif // _LIBCPP___NEW_NEW_HANDLER_H
diff --git a/libcxx/src/new_handler.cpp b/libcxx/src/new_handler.cpp
index 49c21d85f5908..5124cb501c938 100644
--- a/libcxx/src/new_handler.cpp
+++ b/libcxx/src/new_handler.cpp
@@ -11,9 +11,7 @@
 #include "include/atomic_support.h"
 
 #if defined(_LIBCPP_ABI_MICROSOFT)
-#  if !defined(_LIBCPP_ABI_VCRUNTIME)
-#    define _LIBPCPP_DEFINE_NEW_HANDLER
-#  endif
+#  define _LIBPCPP_DEFINE_NEW_HANDLER
 #elif defined(LIBCXX_BUILDING_LIBCXXABI)
 // nothing to do, we use the one from libc++abi
 #elif defined(LIBCXXRT)



More information about the libcxx-commits mailing list