summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2024-09-12 16:38:12 +0200
committerMarc Mutz <marc.mutz@qt.io>2024-09-14 14:40:00 +0200
commitc38e58dcb02cd2273ba3c03c65a6f67b37100777 (patch)
tree4e37822c3c2787523eb4d62d82a39522a92ce671
parent5820d54103d5c432ae8eaae180aefb1988f835ce (diff)
Fix -Wdouble-promotion in FP overload of convertDoubleTo()
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<T>::max)()) { | ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Since we already checked that numeric_limits<T>::max_exponent < numeric_limits<double>::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 <oystein.heskestad@qt.io> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
-rw-r--r--src/corelib/global/qnumeric_p.h2
1 files changed, 1 insertions, 1 deletions
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<T>::max)()) {
+ if (std::fabs(v) > double{(std::numeric_limits<T>::max)()}) {
*value = v < 0 ? -Huge : Huge;
return false;
}