Fix tst_qmath when compiled with C++20
On several platforms std::bit_ceil() returns 1 for input values that would overflow the output. Our test expects 0 though. Since the value is documented as undefined, avoid it. Pick-to: 6.3 6.2 Change-Id: I00556893a8f0e1e24f08f73cd112b56148bc5bd0 Reviewed-by: Marc Mutz <marc.mutz@qt.io>
This commit is contained in:
parent
4082fe8a39
commit
ace9764c99
@ -371,6 +371,8 @@ constexpr inline quint64 qConstexprNextPowerOfTwo(qint64 v)
|
|||||||
constexpr inline quint32 qNextPowerOfTwo(quint32 v)
|
constexpr inline quint32 qNextPowerOfTwo(quint32 v)
|
||||||
{
|
{
|
||||||
#if defined(__cpp_lib_int_pow2) && __cpp_lib_int_pow2 >= 202002L
|
#if defined(__cpp_lib_int_pow2) && __cpp_lib_int_pow2 >= 202002L
|
||||||
|
if (static_cast<qint32>(v) < 0)
|
||||||
|
return 0; // std::bit_ceil() is undefined for values that would overflow, but we document them to be 0
|
||||||
return std::bit_ceil(v + 1);
|
return std::bit_ceil(v + 1);
|
||||||
#elif defined(QT_HAS_BUILTIN_CLZ)
|
#elif defined(QT_HAS_BUILTIN_CLZ)
|
||||||
if (v == 0)
|
if (v == 0)
|
||||||
@ -384,6 +386,8 @@ constexpr inline quint32 qNextPowerOfTwo(quint32 v)
|
|||||||
constexpr inline quint64 qNextPowerOfTwo(quint64 v)
|
constexpr inline quint64 qNextPowerOfTwo(quint64 v)
|
||||||
{
|
{
|
||||||
#if defined(__cpp_lib_int_pow2) && __cpp_lib_int_pow2 >= 202002L
|
#if defined(__cpp_lib_int_pow2) && __cpp_lib_int_pow2 >= 202002L
|
||||||
|
if (static_cast<qint64>(v) < 0)
|
||||||
|
return 0; // std::bit_ceil() is undefined for values that would overflow, but we document them to be 0
|
||||||
return std::bit_ceil(v + 1);
|
return std::bit_ceil(v + 1);
|
||||||
#elif defined(QT_HAS_BUILTIN_CLZLL)
|
#elif defined(QT_HAS_BUILTIN_CLZLL)
|
||||||
if (v == 0)
|
if (v == 0)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user