[libcxx-commits] [libcxx] [libc++] Tweak comments for workaround about `fpclassify` overloads (PR #212388)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Tue Aug 4 08:48:28 PDT 2026


https://github.com/ldionne updated https://github.com/llvm/llvm-project/pull/212388

>From 051277e9058ed0744baeb67778ca1632e573235c Mon Sep 17 00:00:00 2001
From: "A. Jiang" <de34 at live.cn>
Date: Tue, 28 Jul 2026 09:34:51 +0800
Subject: [PATCH 1/2] [libc++] Tweak comments for workaround about `fpclassify`
 overloads

Explaining why we have `_LIBCPP_PREFERRED_OVERLOAD` and template
versions.
---
 libcxx/include/math.h | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/libcxx/include/math.h b/libcxx/include/math.h
index 0aed0db87270c..49368070e5539 100644
--- a/libcxx/include/math.h
+++ b/libcxx/include/math.h
@@ -387,6 +387,12 @@ namespace __math {
 
 // fpclassify
 
+// MS UCRT provides non-template fpclassify overloads for float, double, and long double that are unconditionally
+// non-constexpr.
+// To workaround this, we use _LIBCPP_PREFERRED_OVERLOAD to make our overloads stronger those overloads, which is
+// necessary for constexpr addition in C++23. When _LIBCPP_PREFERRED_OVERLOAD is not supported, we use template
+// overloads as workaround to avoid conflicts.
+
 #      ifdef _LIBCPP_PREFERRED_OVERLOAD
 [[__nodiscard__]] inline _LIBCPP_CONSTEXPR_SINCE_CXX23
 _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD int fpclassify(float __x) _NOEXCEPT {
@@ -409,8 +415,6 @@ fpclassify(_A1 __x) _NOEXCEPT {
   return __x == 0 ? FP_ZERO : FP_NORMAL;
 }
 #      else
-
-// template on non-double overloads to make them weaker than same overloads from MSVC runtime
 template <class = int>
 [[__nodiscard__]] inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI int fpclassify(float __x) _NOEXCEPT {
   return __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL, FP_SUBNORMAL, FP_ZERO, __x);

>From 59568219b1f3fe2824eade19163d80ab3e1263f0 Mon Sep 17 00:00:00 2001
From: Louis Dionne <ldionne.2 at gmail.com>
Date: Tue, 4 Aug 2026 11:48:18 -0400
Subject: [PATCH 2/2] Apply suggestion from @lknknm

Co-authored-by: Lucas Mellone <github.snugness349 at passinbox.com>
---
 libcxx/include/math.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libcxx/include/math.h b/libcxx/include/math.h
index 49368070e5539..9d0642398b7d4 100644
--- a/libcxx/include/math.h
+++ b/libcxx/include/math.h
@@ -389,9 +389,9 @@ namespace __math {
 
 // MS UCRT provides non-template fpclassify overloads for float, double, and long double that are unconditionally
 // non-constexpr.
-// To workaround this, we use _LIBCPP_PREFERRED_OVERLOAD to make our overloads stronger those overloads, which is
+// To workaround this, we use _LIBCPP_PREFERRED_OVERLOAD to make our overloads stronger than those overloads, which is
 // necessary for constexpr addition in C++23. When _LIBCPP_PREFERRED_OVERLOAD is not supported, we use template
-// overloads as workaround to avoid conflicts.
+// overloads as a workaround to avoid conflicts.
 
 #      ifdef _LIBCPP_PREFERRED_OVERLOAD
 [[__nodiscard__]] inline _LIBCPP_CONSTEXPR_SINCE_CXX23



More information about the libcxx-commits mailing list