[libcxx-commits] [libcxx] [libc++] Fix C++23 standard modules when using with `clang-cl` on Windows (PR #148992)

via libcxx-commits libcxx-commits at lists.llvm.org
Tue Jul 15 16:49:23 PDT 2025


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

The following PR fixes a couple of issues and compilation errors when using `libcxx` with `clang-cl` on Windows.

Issues:
- compilation error because of missing definition of `get_new_handler()` in the `ucrt/new.h` that is included by `libcxx/include/__new`
- compilation errors due to `static inline` in functions definition for `ctime` inside `std.cppm.in` and `std.compat.cppm.in` (`std.cppm`, `std.compat.cppm`).

Fixes:
- defining `get_new_handler()` function under the `std` namespace when using `_LIBCPP_ABI_VCRUNTIME`.
- defining `_BUILD_STD_MODULE` before including `<ctime>` inside `std.cppm.in` because MSVC's headers already have a fix in place.
- both `std.cppm` and `std.compat.cppm` are fixed.

This pull request fixes the following issues:
- https://github.com/llvm/llvm-project/issues/64812

>From ed2c4e4947d9f703675acdc0dad3c380fb0a390a Mon Sep 17 00:00:00 2001
From: siradam7th <siradam7th at users.noreply.github.com>
Date: Wed, 16 Jul 2025 00:35:50 +0100
Subject: [PATCH] fix libc++ std modules compilation on Windows using clang-cl

---
 libcxx/include/__new/new_handler.h  | 5 +++++
 libcxx/modules/std.compat/ctime.inc | 6 ++++--
 libcxx/modules/std.cppm.in          | 3 +++
 libcxx/modules/std/ctime.inc        | 6 ++++--
 4 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/libcxx/include/__new/new_handler.h b/libcxx/include/__new/new_handler.h
index 05f4e846c3ef9..2350f9ae9bc19 100644
--- a/libcxx/include/__new/new_handler.h
+++ b/libcxx/include/__new/new_handler.h
@@ -17,6 +17,11 @@
 
 #if defined(_LIBCPP_ABI_VCRUNTIME)
 #  include <new.h>
+// <new.h> does not define 'get_new_handler'
+// which makes the 'std' module build fail, this fixes it
+namespace std {
+_LIBCPP_EXPORTED_FROM_ABI new_handler get_new_handler() _NOEXCEPT;
+}
 #else
 _LIBCPP_BEGIN_UNVERSIONED_NAMESPACE_STD
 typedef void (*new_handler)();
diff --git a/libcxx/modules/std.compat/ctime.inc b/libcxx/modules/std.compat/ctime.inc
index eba8234a08969..7547b055b6807 100644
--- a/libcxx/modules/std.compat/ctime.inc
+++ b/libcxx/modules/std.compat/ctime.inc
@@ -14,15 +14,17 @@ export {
 
   using ::timespec _LIBCPP_USING_IF_EXISTS;
   using ::tm _LIBCPP_USING_IF_EXISTS;
-
   using ::asctime _LIBCPP_USING_IF_EXISTS;
   using ::clock _LIBCPP_USING_IF_EXISTS;
+  using ::strftime _LIBCPP_USING_IF_EXISTS;
+
+#ifndef _LIBCPP_ABI_VCRUNTIME
   using ::ctime _LIBCPP_USING_IF_EXISTS;
   using ::difftime _LIBCPP_USING_IF_EXISTS;
   using ::gmtime _LIBCPP_USING_IF_EXISTS;
   using ::localtime _LIBCPP_USING_IF_EXISTS;
   using ::mktime _LIBCPP_USING_IF_EXISTS;
-  using ::strftime _LIBCPP_USING_IF_EXISTS;
   using ::time _LIBCPP_USING_IF_EXISTS;
   using ::timespec_get _LIBCPP_USING_IF_EXISTS;
+#endif
 } // export
diff --git a/libcxx/modules/std.cppm.in b/libcxx/modules/std.cppm.in
index 984b18321923c..f19dc07169fda 100644
--- a/libcxx/modules/std.cppm.in
+++ b/libcxx/modules/std.cppm.in
@@ -51,6 +51,9 @@ module;
 #include <cstdio>
 #include <cstdlib>
 #include <cstring>
+#ifdef _LIBCPP_ABI_VCRUNTIME
+#define _BUILD_STD_MODULE
+#endif
 #include <ctime>
 #include <cuchar>
 #include <cwchar>
diff --git a/libcxx/modules/std/ctime.inc b/libcxx/modules/std/ctime.inc
index 5bfa61917e5f2..e9f8ecb6ec63e 100644
--- a/libcxx/modules/std/ctime.inc
+++ b/libcxx/modules/std/ctime.inc
@@ -14,15 +14,17 @@ export namespace std {
 
   using std::timespec _LIBCPP_USING_IF_EXISTS;
   using std::tm _LIBCPP_USING_IF_EXISTS;
-
   using std::asctime _LIBCPP_USING_IF_EXISTS;
   using std::clock _LIBCPP_USING_IF_EXISTS;
+  using std::strftime _LIBCPP_USING_IF_EXISTS;
+
+#ifndef _LIBCPP_ABI_VCRUNTIME
   using std::ctime _LIBCPP_USING_IF_EXISTS;
   using std::difftime _LIBCPP_USING_IF_EXISTS;
   using std::gmtime _LIBCPP_USING_IF_EXISTS;
   using std::localtime _LIBCPP_USING_IF_EXISTS;
   using std::mktime _LIBCPP_USING_IF_EXISTS;
-  using std::strftime _LIBCPP_USING_IF_EXISTS;
   using std::time _LIBCPP_USING_IF_EXISTS;
   using std::timespec_get _LIBCPP_USING_IF_EXISTS;
+#endif
 } // namespace std



More information about the libcxx-commits mailing list