Skip to content

Commit f434546

Browse files
authored
Fix compilation on clang-21 / libc++-21 (fmtlib#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>`.
1 parent 1ef8348 commit f434546

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

include/fmt/format.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
# include <cmath> // std::signbit
4545
# include <cstddef> // std::byte
4646
# include <cstdint> // uint32_t
47+
# include <cstdlib> // std::malloc, std::free
4748
# include <cstring> // std::memcpy
4849
# include <limits> // std::numeric_limits
4950
# include <new> // std::bad_alloc
@@ -755,12 +756,12 @@ template <typename T> struct allocator : private std::decay<void> {
755756

756757
T* allocate(size_t n) {
757758
FMT_ASSERT(n <= max_value<size_t>() / sizeof(T), "");
758-
T* p = static_cast<T*>(malloc(n * sizeof(T)));
759+
T* p = static_cast<T*>(std::malloc(n * sizeof(T)));
759760
if (!p) FMT_THROW(std::bad_alloc());
760761
return p;
761762
}
762763

763-
void deallocate(T* p, size_t) { free(p); }
764+
void deallocate(T* p, size_t) { std::free(p); }
764765
};
765766

766767
} // namespace detail

0 commit comments

Comments
 (0)