From ace9764c995be9eb7cb42296a2885c72fb1005f3 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Sat, 5 Feb 2022 14:32:05 +0100 Subject: [PATCH] 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 --- src/corelib/kernel/qmath.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/corelib/kernel/qmath.h b/src/corelib/kernel/qmath.h index 5e8d4fc2767..2171a4ed93e 100644 --- a/src/corelib/kernel/qmath.h +++ b/src/corelib/kernel/qmath.h @@ -371,6 +371,8 @@ constexpr inline quint64 qConstexprNextPowerOfTwo(qint64 v) constexpr inline quint32 qNextPowerOfTwo(quint32 v) { #if defined(__cpp_lib_int_pow2) && __cpp_lib_int_pow2 >= 202002L + if (static_cast(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); #elif defined(QT_HAS_BUILTIN_CLZ) if (v == 0) @@ -384,6 +386,8 @@ constexpr inline quint32 qNextPowerOfTwo(quint32 v) constexpr inline quint64 qNextPowerOfTwo(quint64 v) { #if defined(__cpp_lib_int_pow2) && __cpp_lib_int_pow2 >= 202002L + if (static_cast(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); #elif defined(QT_HAS_BUILTIN_CLZLL) if (v == 0)