diff --git a/src/corelib/text/qlocale.cpp b/src/corelib/text/qlocale.cpp index 5abc4d3a09..2999793857 100644 --- a/src/corelib/text/qlocale.cpp +++ b/src/corelib/text/qlocale.cpp @@ -3642,20 +3642,17 @@ QString QLocaleData::signPrefix(bool negative, unsigned flags) const return {}; } -QString QLocaleData::longLongToString(qlonglong l, int precision, +QString QLocaleData::longLongToString(qlonglong n, int precision, int base, int width, unsigned flags) const { - bool negative = l < 0; + bool negative = n < 0; -QT_WARNING_PUSH - /* "unary minus operator applied to unsigned type, result still unsigned" */ -QT_WARNING_DISABLE_MSVC(4146) /* Negating std::numeric_limits::min() hits undefined behavior, so - taking an absolute value has to cast to unsigned to change sign. + taking an absolute value has to take a slight detour. */ - QString numStr = qulltoa(negative ? -qulonglong(l) : qulonglong(l), base, zeroDigit()); -QT_WARNING_POP + QString numStr = qulltoa(negative ? 1u + qulonglong(-(n + 1)) : qulonglong(n), + base, zeroDigit()); return applyIntegerFormatting(std::move(numStr), negative, precision, base, width, flags); } diff --git a/src/corelib/text/qstring.cpp b/src/corelib/text/qstring.cpp index 8dbf996f73..938712a36d 100644 --- a/src/corelib/text/qstring.cpp +++ b/src/corelib/text/qstring.cpp @@ -7374,16 +7374,12 @@ QString QString::number(qlonglong n, int base) base = 10; } #endif -QT_WARNING_PUSH - /* "unary minus operator applied to unsigned type, result still unsigned" */ -QT_WARNING_DISABLE_MSVC(4146) bool negative = n < 0; /* Negating std::numeric_limits::min() hits undefined behavior, so - taking an absolute value has to cast to unsigned to change sign. + taking an absolute value has to take a slight detour. */ - return qulltoBasicLatin(negative ? -qulonglong(n) : qulonglong(n), base, negative); -QT_WARNING_POP + return qulltoBasicLatin(negative ? 1u + qulonglong(-(n + 1)) : qulonglong(n), base, negative); } /*!