From e851b6ea2c658a9fe6f704b15a07277457b1bb07 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Wed, 9 Feb 2022 10:12:08 -0800 Subject: QLibrary: Suppress GCC 12 warning about dangling pointer access MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Introduced in commit d07742f333df89dc399fc5d9cabf2bdef0b346c5. Reported by GCC 12: qlibrary.cpp:672:9: error: dangling pointer to ‘candidates’ may be used [-Werror=dangling-pointer=] 672 | if (isValidSuffix(*it++)) | ^~ qlibrary.cpp:634:29: note: ‘candidates’ declared here 634 | const QLatin1String candidates[] = { | ^~~~~~~~~~ This is a false positive report because the lambda does not return a pointer or iterator. But it's a good update anyway to keep the array outside the lambda, so it won't be recreated every time. See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104492 Change-Id: I74249c52dc02478ba93cfffd16d230abd1bf6166 Reviewed-by: Marc Mutz (cherry picked from commit 81b9ee66b8e40ed145185fe46b7c91929688cafd) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/plugin/qlibrary.cpp | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/corelib/plugin/qlibrary.cpp b/src/corelib/plugin/qlibrary.cpp index 9f89abdf01..6e08e73f23 100644 --- a/src/corelib/plugin/qlibrary.cpp +++ b/src/corelib/plugin/qlibrary.cpp @@ -629,29 +629,30 @@ bool QLibrary::isLibrary(const QString &fileName) if (completeSuffix.isEmpty()) return false; - auto isValidSuffix = [](QStringView s) { - // if this throws an empty-array error, you need to fix the #ifdef's: - const QLatin1String candidates[] = { + // if this throws an empty-array error, you need to fix the #ifdef's: + const QLatin1String candidates[] = { # if defined(Q_OS_HPUX) /* See "HP-UX Linker and Libraries User's Guide", section "Link-time Differences between PA-RISC and IPF": "In PA-RISC (PA-32 and PA-64) shared libraries are suffixed with .sl. In IPF (32-bit and 64-bit), the shared libraries are suffixed with .so. For compatibility, the IPF linker also supports the .sl suffix." - */ - QLatin1String("sl"), +*/ + QLatin1String("sl"), # if defined __ia64 - QLatin1String("so"), + QLatin1String("so"), # endif # elif defined(Q_OS_AIX) - QLatin1String("a"), - QLatin1String("so"), + QLatin1String("a"), + QLatin1String("so"), # elif defined(Q_OS_DARWIN) - QLatin1String("so"), - QLatin1String("bundle"), + QLatin1String("so"), + QLatin1String("bundle"), # elif defined(Q_OS_UNIX) - QLatin1String("so"), + QLatin1String("so"), # endif - }; // candidates + }; // candidates + + auto isValidSuffix = [&candidates](QStringView s) { return std::find(std::begin(candidates), std::end(candidates), s) != std::end(candidates); }; -- cgit v1.2.3