From c3889538c7ab84630dfd0ef4e5bc53a48a2a6b47 Mon Sep 17 00:00:00 2001 From: chrchr-github Date: Sat, 27 Apr 2024 14:14:15 +0200 Subject: [PATCH 1/3] Fix #12662 FP unreadVariable with QMap iterator --- lib/fwdanalysis.cpp | 2 ++ test/cfg/qt.cpp | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/lib/fwdanalysis.cpp b/lib/fwdanalysis.cpp index 97337c3ab40..256f2e32a1b 100644 --- a/lib/fwdanalysis.cpp +++ b/lib/fwdanalysis.cpp @@ -497,6 +497,8 @@ bool FwdAnalysis::possiblyAliased(const Token *expr, const Token *startToken) co return true; if (Token::simpleMatch(expr, ". *")) return true; + if (expr->str() == "(" && Token::simpleMatch(expr->astOperand1(), ".")) + return true; const bool macro = false; const bool pure = false; diff --git a/test/cfg/qt.cpp b/test/cfg/qt.cpp index d89fc4a8443..a955a9ee264 100644 --- a/test/cfg/qt.cpp +++ b/test/cfg/qt.cpp @@ -1,4 +1,5 @@ + // Test library configuration for qt.cfg // // Usage: @@ -775,3 +776,11 @@ void unusedVariable_qtContainers() // #10689 QLatin1String ql1s; } +void unreadVariable_QMapIterator(QMap& m) +{ + auto it = m.find("abc"); // #12662 + if (it != m.end()) { + delete it.value(); + it.value() = new QObject(); + } +} From 5420aff7e1262a30b7bc2180cebe64d2b9284770 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Sat, 27 Apr 2024 14:16:22 +0200 Subject: [PATCH 2/3] Update qt.cpp --- test/cfg/qt.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/test/cfg/qt.cpp b/test/cfg/qt.cpp index a955a9ee264..e4271021ca9 100644 --- a/test/cfg/qt.cpp +++ b/test/cfg/qt.cpp @@ -1,5 +1,4 @@ - // Test library configuration for qt.cfg // // Usage: From a9fb465c871b9ffc2f4cb96bbcfab210e33c5d5e Mon Sep 17 00:00:00 2001 From: chrchr-github Date: Sat, 27 Apr 2024 14:45:32 +0200 Subject: [PATCH 3/3] Suppress checkLibraryFunction --- test/cfg/qt.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/cfg/qt.cpp b/test/cfg/qt.cpp index e4271021ca9..f77ea2e88ba 100644 --- a/test/cfg/qt.cpp +++ b/test/cfg/qt.cpp @@ -779,7 +779,9 @@ void unreadVariable_QMapIterator(QMap& m) { auto it = m.find("abc"); // #12662 if (it != m.end()) { + // cppcheck-suppress checkLibraryFunction // TODO delete it.value(); + // cppcheck-suppress checkLibraryFunction it.value() = new QObject(); } }