From 831541d935bcb2d97a91834351b1129683f3d44d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kai=20K=C3=B6hne?= Date: Tue, 11 Jul 2023 16:52:47 +0200 Subject: Use if constexpr () in public headers Use if constexpr() for conditions that are constexpr. This fixes MSVC warning C4127, which is enabled for compiler warning level 4 (/W4). While at it, don't narrow down the type from size_t to quint32. Change-Id: I95403e5d60173ed48478532dcdcc09ecd666fbe0 Reviewed-by: Marc Mutz (cherry picked from commit 37df21126dcf94bb5aaaa8f1e41cf458630be86d) Reviewed-by: Qt Cherry-pick Bot --- src/serialbus/qmodbuspdu.h | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/serialbus/qmodbuspdu.h b/src/serialbus/qmodbuspdu.h index 7a2e46c..61ea3a7 100644 --- a/src/serialbus/qmodbuspdu.h +++ b/src/serialbus/qmodbuspdu.h @@ -133,19 +133,21 @@ private: template void encode(Args ... newData) { m_data.clear(); - Q_CONSTEXPR quint32 argCount = sizeof...(Args); - if (argCount > 0) { + constexpr size_t argCount = sizeof...(Args); + if constexpr (argCount > 0) { QDataStream stream(&m_data, QIODevice::WriteOnly); char tmp[argCount] = { (encode(&stream, newData), void(), '0')... }; Q_UNUSED(tmp); } } template void decode(Args ... newData) const { - Q_CONSTEXPR quint32 argCount = sizeof...(Args); - if (argCount > 0 && !m_data.isEmpty()) { - QDataStream stream(m_data); - char tmp[argCount] = { (decode(&stream, newData), void(), '0')... }; - Q_UNUSED(tmp); + constexpr size_t argCount = sizeof...(Args); + if constexpr (argCount > 0) { + if (!m_data.isEmpty()) { + QDataStream stream(m_data); + char tmp[argCount] = { (decode(&stream, newData), void(), '0')... }; + Q_UNUSED(tmp); + } } } -- cgit v1.2.3