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.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> (cherry picked from commit c38e58dcb02cd2273ba3c03c65a6f67b37100777) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
c36b24b087
commit
5d6a204789
@ -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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user