dev-libs/libfmt: fix build with clang

1. undeclared malloc/free error with libc++-21
2. specializations for std::is_floating_point is UB

Closes: https://bugs.gentoo.org/969530
Signed-off-by: Z. Liu <zhixu.liu@gmail.com>
Part-of: https://codeberg.org/gentoo/gentoo/pulls/2219
Merges: https://codeberg.org/gentoo/gentoo/pulls/2219
Signed-off-by: Sam James <sam@gentoo.org>
This commit is contained in:
Z. Liu
2026-11-07 05:18:25 +00:00
committed by Sam James
parent a6e6c5768e
commit 32f810fbc3
3 changed files with 115 additions and 1 deletions
@@ -0,0 +1,72 @@
https://github.com/fmtlib/fmt/issues/4417
From 9db5e4df22d47ea6741913b5ca618687133494fe Mon Sep 17 00:00:00 2001
From: Victor Zverovich <viz@meta.com>
Date: Sat, 26 Apr 2025 08:17:05 -0700
Subject: [PATCH] Don't specialize std::is_floating_point
---
include/fmt/format.h | 11 +++++------
test/format-impl-test.cc | 4 ++--
2 files changed, 7 insertions(+), 8 deletions(-)
diff --git a/include/fmt/format.h b/include/fmt/format.h
index 2596e3a8..b2fdd3d6 100644
--- a/include/fmt/format.h
+++ b/include/fmt/format.h
@@ -721,11 +721,10 @@ struct float128 {};
template <typename T> using is_float128 = std::is_same<T, float128>;
-template <typename T>
-using is_floating_point =
- bool_constant<std::is_floating_point<T>::value || is_float128<T>::value>;
+template <typename T> struct is_floating_point : std::is_floating_point<T> {};
+template <> struct is_floating_point<float128> : std::true_type {};
-template <typename T, bool = std::is_floating_point<T>::value>
+template <typename T, bool = is_floating_point<T>::value>
struct is_fast_float : bool_constant<std::numeric_limits<T>::is_iec559 &&
sizeof(T) <= sizeof(double)> {};
template <typename T> struct is_fast_float<T, false> : std::false_type {};
@@ -2472,8 +2471,8 @@ template <typename T>
struct has_isfinite<T, enable_if_t<sizeof(std::isfinite(T())) != 0>>
: std::true_type {};
-template <typename T, FMT_ENABLE_IF(std::is_floating_point<T>::value&&
- has_isfinite<T>::value)>
+template <typename T,
+ FMT_ENABLE_IF(is_floating_point<T>::value&& has_isfinite<T>::value)>
FMT_CONSTEXPR20 auto isfinite(T value) -> bool {
constexpr T inf = T(std::numeric_limits<double>::infinity());
if (is_constant_evaluated())
diff --git a/test/format-impl-test.cc b/test/format-impl-test.cc
index 4ebf2a6e..2be15d00 100644
--- a/test/format-impl-test.cc
+++ b/test/format-impl-test.cc
@@ -307,7 +307,6 @@ struct slow_float {
auto format_as(slow_float f) -> float { return f; }
namespace std {
-template <> struct is_floating_point<double_double> : std::true_type {};
template <> struct numeric_limits<double_double> {
// is_iec559 is true for double-double in libstdc++.
static constexpr bool is_iec559 = true;
@@ -315,12 +314,13 @@ template <> struct numeric_limits<double_double> {
static constexpr int digits10 = 33;
};
-template <> struct is_floating_point<slow_float> : std::true_type {};
template <> struct numeric_limits<slow_float> : numeric_limits<float> {};
} // namespace std
FMT_BEGIN_NAMESPACE
namespace detail {
+template <> struct is_floating_point<double_double> : std::true_type {};
+template <> struct is_floating_point<slow_float> : std::true_type {};
template <> struct is_fast_float<slow_float> : std::false_type {};
namespace dragonbox {
template <> struct float_info<slow_float> {
--
2.49.1
@@ -0,0 +1,37 @@
From https://github.com/fmtlib/fmt/commit/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>`.
--- a/include/fmt/format.h
+++ b/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
@@ -755,12 +756,12 @@ template <typename T> struct allocator : private std::decay<void> {
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
+6 -1
View File
@@ -1,4 +1,4 @@
# Copyright 1999-2025 Gentoo Authors
# Copyright 1999-2026 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
EAPI=8
@@ -22,6 +22,11 @@ SLOT="0/${PV}"
IUSE="test"
RESTRICT="!test? ( test )"
PATCHES=(
"${FILESDIR}/libfmt-11.2.0-libcxx-21-cstdlib.patch"
"${FILESDIR}/${P}-libcxx-no-specialize-is-floating-point.patch"
)
multilib_src_configure() {
append-lfs-flags
local mycmakeargs=(