From 527ff9028ddfd528d777db56f9cc8559c6ea4db6 Mon Sep 17 00:00:00 2001 From: Cary Phillips Date: Sun, 1 Mar 2026 12:34:56 -0800 Subject: [PATCH] Suppress C++23 float_denorm_style deprecation warning in numeric_limits Part of an effort to get CI building without warnings. C++23 deprecates std::float_denorm_style and std::denorm_present but does not remove them or provide a replacement; std::numeric_limits still requires has_denorm to be of that type, so we must use it, which leads to a warning: src/Imath/half.h:948:22: warning: 'float_denorm_style' is deprecated [-Wdeprecated-declarations] static constexpr float_denorm_style has_denorm = denorm_present; ^ Suppress the warning for this use and only when building in C++23 (or later): wrap the has_denorm declaration in compiler-specific pragmas (GCC/Clang -Wdeprecated-declarations, MSVC 4996) guarded by (__cplusplus >= 202302L) and the compiler macro. Pre-C++23 builds are unchanged and use no pragmas. Made-with: Cursor Signed-off-by: Cary Phillips --- src/Imath/half.h | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/Imath/half.h b/src/Imath/half.h index cf880686..611d468a 100644 --- a/src/Imath/half.h +++ b/src/Imath/half.h @@ -945,7 +945,24 @@ template <> class numeric_limits static constexpr bool has_infinity = true; static constexpr bool has_quiet_NaN = true; static constexpr bool has_signaling_NaN = true; - static constexpr float_denorm_style has_denorm = denorm_present; + + // C++23 deprecates std::float_denorm_style and std::denorm_present but does not remove + // them or provide a replacement. std::numeric_limits still requires has_denorm to be of + // that type, so we must use it. Suppress the warning only in C++23 until the standard + // provides an alternative. +#if (defined(__clang__) || defined(__GNUC__)) && (__cplusplus >= 202302L) +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wdeprecated-declarations" +#elif defined(_MSC_VER) && defined(_MSVC_LANG) && (_MSVC_LANG >= 202302L) +# pragma warning(push) +# pragma warning(disable : 4996) +#endif + static constexpr float_denorm_style has_denorm = denorm_present; +#if (defined(__clang__) || defined(__GNUC__)) && (__cplusplus >= 202302L) +# pragma GCC diagnostic pop +#elif defined(_MSC_VER) && defined(_MSVC_LANG) && (_MSVC_LANG >= 202302L) +# pragma warning(pop) +#endif static constexpr bool has_denorm_loss = false; static constexpr IMATH_INTERNAL_NAMESPACE::half infinity () IMATH_NOEXCEPT {