diff options
author | Kai Köhne <kai.koehne@qt.io> | 2023-07-11 16:52:47 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2023-07-17 11:18:05 +0000 |
commit | 831541d935bcb2d97a91834351b1129683f3d44d (patch) | |
tree | e961a632a8928843e7b4abcaec51c71e02fc2992 | |
parent | 1c6686c1c84eefe9b0eab0591489af4e0b67be8e (diff) |
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 <marc.mutz@qt.io>
(cherry picked from commit 37df21126dcf94bb5aaaa8f1e41cf458630be86d)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | src/serialbus/qmodbuspdu.h | 16 |
1 files 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<typename ... Args> 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<typename ... Args> 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); + } } } |