From 922370814a0c8f258153c560ba7797f481531eee Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Fri, 1 Mar 2024 10:17:38 -0800 Subject: [PATCH] qfloat16: make native std::numeric_limits constexpr MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In C++23 with std::float16_t present (QFLOAT16_IS_NATIVE), the _limit_xxxx() methods in qfloat16 need to set the native type, not rely on the union trick because that isn't allowed in constexpr mode. in ‘constexpr’ expansion of ‘operator<=>(Max, std::numeric_limits::max())’ qfloat16.h:209:5: in ‘constexpr’ expansion of ‘compareThreeWay((* & lhs), ((double)rhs))’ qfloat16.h:209:5: in ‘constexpr’ expansion of ‘(& lhs)->qfloat16::operator NativeType()’ error: accessing ‘qfloat16::::nf’ member instead of initialized ‘qfloat16::::b16’ member in constant expression Change-Id: I01ec3c774d9943adb903fffd17b8b6ceed6ef9e2 Reviewed-by: Allan Sandfeld Jensen (cherry picked from commit 48cd6867578ef372bbacb16081414b506cdb5b38) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/global/qfloat16.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/corelib/global/qfloat16.h b/src/corelib/global/qfloat16.h index 80b2543dc14..a9527544d7b 100644 --- a/src/corelib/global/qfloat16.h +++ b/src/corelib/global/qfloat16.h @@ -118,7 +118,13 @@ private: NativeType nf; #endif }; - constexpr inline explicit qfloat16(Wrap nibble) noexcept : b16(nibble.b16) {} + constexpr inline explicit qfloat16(Wrap nibble) noexcept : +#if QFLOAT16_IS_NATIVE && defined(__cpp_lib_bit_cast) + nf(std::bit_cast(nibble.b16)) +#else + b16(nibble.b16) +#endif + {} Q_CORE_EXPORT static const quint32 mantissatable[]; Q_CORE_EXPORT static const quint32 exponenttable[];