From 7a7804d4b454021d68d1d5138d134ef62abfcdb3 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 20 Dec 2024 20:11:31 +0100 Subject: [PATCH] QDecompressHelper: fix compilation with GCC 9 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit GCC 9 doesn't accept [[unlikely]] between the (condition) and the compound-statement of an if, in both C++17 and C++20 modes: qdecompresshelper.cpp: In member function ‘qsizetype QDecompressHelper::readZLib(char*, qsizetype)’: qcompilerdetection.h:1048:31: error: attributes at the beginning of statement are ignored [-Werror=attributes] 1048 | # define Q_UNLIKELY_BRANCH [[unlikely]] | ^~~~~~~~~~~~ qdecompresshelper.cpp:597:54: note: in expansion of macro ‘Q_UNLIKELY_BRANCH’ 597 | if (ret == Z_DATA_ERROR && !triedRawDeflate) Q_UNLIKELY_BRANCH { | ^~~~~~~~~~~~~~~~~ See also https://stackoverflow.com/questions/51797959/how-to-use-c20s-likely-unlikely-attribute-in-if-else-statement Put it into the compound-statement instead, then GCC 9 accepts it. The two are equivalent, because [[likely]] marks a path, and there is no selection statement between the two positions. Amends 5ae84d0afbd3690a2c003d06d920566a5d56dc8c. Pick-to: 6.9 Change-Id: Iac1970219c98a1c26e450dfe6bad6583e4d32c29 Reviewed-by: Thiago Macieira --- src/network/access/qdecompresshelper.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/network/access/qdecompresshelper.cpp b/src/network/access/qdecompresshelper.cpp index 0edcc49dc73..0bb2b27152e 100644 --- a/src/network/access/qdecompresshelper.cpp +++ b/src/network/access/qdecompresshelper.cpp @@ -594,7 +594,7 @@ qsizetype QDecompressHelper::readZLib(char *data, const qsizetype maxSize) // also an error. // in the case where we get Z_DATA_ERROR this could be because we received raw deflate // compressed data. - if (ret == Z_DATA_ERROR && !triedRawDeflate) Q_UNLIKELY_BRANCH { + if (ret == Z_DATA_ERROR && !triedRawDeflate) { Q_UNLIKELY_BRANCH inflateEnd(inflateStream); triedRawDeflate = true; inflateStream->zalloc = Z_NULL; @@ -768,7 +768,7 @@ qsizetype QDecompressHelper::readZstandard(char *data, const qsizetype maxSize) qsizetype bytesDecoded = 0; while (outBuf.pos < outBuf.size && (inBuf.pos < inBuf.size || decoderHasData)) { size_t retValue = ZSTD_decompressStream(zstdStream, &outBuf, &inBuf); - if (ZSTD_isError(retValue)) Q_UNLIKELY_BRANCH { + if (ZSTD_isError(retValue)) { Q_UNLIKELY_BRANCH errorStr = QCoreApplication::translate("QHttp", "ZStandard error: %1") .arg(QUtf8StringView{ZSTD_getErrorName(retValue)}); return -1;