From c38e58dcb02cd2273ba3c03c65a6f67b37100777 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 12 Sep 2024 16:38:12 +0200 Subject: [PATCH] Fix -Wdouble-promotion in FP overload of convertDoubleTo() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Found by applying headercheck to private headers. Says GCC: global/qnumeric_p.h: In instantiation of ‘[...] {anonymous}::convertDoubleTo(double, T*, bool) [with T = float; [...]]’: text/qlocale_p.h:312:51: required from here global/qnumeric_p.h:390:22: error: implicit conversion from ‘float’ to ‘double’ to match other operand of binary expression [-Werror=double-promotion] 390 | if (std::fabs(v) > (std::numeric_limits::max)()) { | ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Since we already checked that numeric_limits::max_exponent < numeric_limits::max_exponent at this point (see constexpr-if at the top of this function template), we can assume that the cast of the RHS of the relational operator to double is safe. Use braced initialization to statically assert that this is, indeed, the case. Amends 1e43b64a7a5c3823a6bdcb8d0cd28a17955939a2 and a14bba6803f674edede596eaeb5a46feed0f889e. Pick-to: 6.8 6.7 6.5 6.2 5.15 Task-number: QTBUG-126219 Change-Id: If2b53d9b8ea7ebfcecec603408681eeffb9aaff6 Reviewed-by: Øystein Heskestad Reviewed-by: Ulf Hermann --- src/corelib/global/qnumeric_p.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/corelib/global/qnumeric_p.h b/src/corelib/global/qnumeric_p.h index 8414a681fc7..47edc9573f9 100644 --- a/src/corelib/global/qnumeric_p.h +++ b/src/corelib/global/qnumeric_p.h @@ -384,7 +384,7 @@ convertDoubleTo(double v, T *value, bool allow_precision_upgrade = true) // Check for in-range value to ensure the conversion is not UB (see the // comment above for Standard language). - if (std::fabs(v) > (std::numeric_limits::max)()) { + if (std::fabs(v) > double{(std::numeric_limits::max)()}) { *value = v < 0 ? -Huge : Huge; return false; }