Skip to content

Commit e4f7087

Browse files
Fix #12662 FP unreadVariable with QMap iterator (#6354)
1 parent b3f3606 commit e4f7087

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

lib/fwdanalysis.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,8 @@ bool FwdAnalysis::possiblyAliased(const Token *expr, const Token *startToken) co
498498
return true;
499499
if (Token::simpleMatch(expr, ". *"))
500500
return true;
501+
if (expr->str() == "(" && Token::simpleMatch(expr->astOperand1(), "."))
502+
return true;
501503

502504
const bool macro = false;
503505
const bool pure = false;

test/cfg/qt.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,3 +775,13 @@ void unusedVariable_qtContainers() // #10689
775775
QLatin1String ql1s;
776776
}
777777

778+
void unreadVariable_QMapIterator(QMap<QString, QObject*>& m)
779+
{
780+
auto it = m.find("abc"); // #12662
781+
if (it != m.end()) {
782+
// cppcheck-suppress checkLibraryFunction // TODO
783+
delete it.value();
784+
// cppcheck-suppress checkLibraryFunction
785+
it.value() = new QObject();
786+
}
787+
}

0 commit comments

Comments
 (0)