From 4732c9300be2f7c6cb5254bf74c52f552d810e7a Mon Sep 17 00:00:00 2001 From: Liang Qi Date: Mon, 9 Jan 2023 16:55:07 +0100 Subject: [PATCH] QOffsetStringArray: fix -Werror=type-limits GCC complains: qoffsetstringarray_p.h:85:27: error: comparison is always false due to limited range of data type [-Werror=type-limits] 85 | if constexpr (Highest <= (std::numeric_limits::max)()) { | ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Fix by casting the RHS (of limited-range type) to size_t, the type of the LHS. Fixes: QTBUG-109875 Change-Id: I494ea544b8b3bfd877443119eebc160eb2f8e063 Reviewed-by: Giuseppe D'Angelo Reviewed-by: Marc Mutz (cherry picked from commit cf145a34b494e08a10271de277f6c4e62b54ea4f) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/tools/qoffsetstringarray_p.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/corelib/tools/qoffsetstringarray_p.h b/src/corelib/tools/qoffsetstringarray_p.h index 3272e4dce9e..9103606a137 100644 --- a/src/corelib/tools/qoffsetstringarray_p.h +++ b/src/corelib/tools/qoffsetstringarray_p.h @@ -81,9 +81,11 @@ private: namespace QtPrivate { template constexpr auto minifyValue() { - if constexpr (Highest <= (std::numeric_limits::max)()) { + constexpr size_t max8 = (std::numeric_limits::max)(); + constexpr size_t max16 = (std::numeric_limits::max)(); + if constexpr (Highest <= max8) { return quint8(Highest); - } else if constexpr (Highest <= (std::numeric_limits::max)()) { + } else if constexpr (Highest <= max16) { return quint16(Highest); } else { // int is probably enough for everyone