summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel/qmath.h
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2022-02-07 11:17:11 +0100
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2022-02-17 17:20:34 +0000
commit65a02da1b5390e6c91a15379f6e87add37eeeeae (patch)
tree4ef80984ed9c33e3c94b59507eefd94a3ccae3f4 /src/corelib/kernel/qmath.h
parent4cdfe6f117e15a1951d8b336afa2b7ed53d44e3a (diff)
Make large inputs to qNextPowerOfTwo give undefined output
Fixing documentation and removing tests. [ChangeLog][Important Behavior Changes] The qNextPowerOfTwo() functions now have preconditions. Change-Id: If6d5e8bee66826910e89be7cac388a1f0422ebfd Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/kernel/qmath.h')
-rw-r--r--src/corelib/kernel/qmath.h6
1 files changed, 2 insertions, 4 deletions
diff --git a/src/corelib/kernel/qmath.h b/src/corelib/kernel/qmath.h
index 2171a4ed93..ef0784a947 100644
--- a/src/corelib/kernel/qmath.h
+++ b/src/corelib/kernel/qmath.h
@@ -370,9 +370,8 @@ constexpr inline quint64 qConstexprNextPowerOfTwo(qint64 v)
constexpr inline quint32 qNextPowerOfTwo(quint32 v)
{
+ Q_ASSERT(static_cast<qint32>(v) >= 0); // There is a next power of two
#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);
#elif defined(QT_HAS_BUILTIN_CLZ)
if (v == 0)
@@ -385,9 +384,8 @@ constexpr inline quint32 qNextPowerOfTwo(quint32 v)
constexpr inline quint64 qNextPowerOfTwo(quint64 v)
{
+ Q_ASSERT(static_cast<qint64>(v) >= 0); // There is a next power of two
#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);
#elif defined(QT_HAS_BUILTIN_CLZLL)
if (v == 0)