From f4345467fce7edbc6b36c3fa1cf197a67be617e2 Mon Sep 17 00:00:00 2001
From: Remy Jette <remy@remyjette.com>
Date: Sat, 21 Jun 2025 07:28:14 -0700
Subject: [PATCH] Fix compilation on clang-21 / libc++-21 (#4477)

`<cstdlib>` was not being included, so malloc and free were only declared
via transitive includes. Some includes changed in the latest libc++-21
build which broke fmt.

Also changed `malloc`/`free` to `std::malloc` and `std::free`, as
putting those symbols in the global namespace is optional for the
implementation when including `<cstdlib>`.

Upstream-Status: Backport [https://github.com/fmtlib/fmt/pull/4477]
Signed-off-by: Khem Raj <raj.khem@gmail.com>
---
 include/fmt/format.h | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Index: fmt-11.2.0/include/fmt/format.h
===================================================================
--- fmt-11.2.0.orig/include/fmt/format.h
+++ fmt-11.2.0/include/fmt/format.h
@@ -44,6 +44,7 @@
 #  include <cmath>    // std::signbit
 #  include <cstddef>  // std::byte
 #  include <cstdint>  // uint32_t
+#  include <cstdlib>  // std::malloc, std::free
 #  include <cstring>  // std::memcpy
 #  include <limits>   // std::numeric_limits
 #  include <new>      // std::bad_alloc
@@ -744,12 +745,12 @@ template <typename T> struct allocator {
 
   T* allocate(size_t n) {
     FMT_ASSERT(n <= max_value<size_t>() / sizeof(T), "");
-    T* p = static_cast<T*>(malloc(n * sizeof(T)));
+    T* p = static_cast<T*>(std::malloc(n * sizeof(T)));
     if (!p) FMT_THROW(std::bad_alloc());
     return p;
   }
 
-  void deallocate(T* p, size_t) { free(p); }
+  void deallocate(T* p, size_t) { std::free(p); }
 };
 
 }  // namespace detail
