From 3172f5491c26269c80b296cc2be34ec262fb10b8 Mon Sep 17 00:00:00 2001 From: chrchr Date: Tue, 19 Mar 2024 14:48:19 +0100 Subject: [PATCH] Fix #12529 false negative: unreadVariable with library type --- cfg/qt.cfg | 6 +++--- lib/checkunusedvar.cpp | 11 +++++++++-- test/cfg/qt.cpp | 11 +++++++++++ 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/cfg/qt.cfg b/cfg/qt.cfg index 69bc205a316a..8c2d34073b07 100644 --- a/cfg/qt.cfg +++ b/cfg/qt.cfg @@ -5236,12 +5236,12 @@ QApplication QMutexLocker - QRectF - QSizeF - QPointF QRect + QRectF QSize + QSizeF QPoint + QPointF QRegion diff --git a/lib/checkunusedvar.cpp b/lib/checkunusedvar.cpp index 7d7ccd7b0235..57d688833048 100644 --- a/lib/checkunusedvar.cpp +++ b/lib/checkunusedvar.cpp @@ -713,10 +713,17 @@ void CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(const Scope* const type = Variables::pointer; else if (mTokenizer->isC() || i->typeEndToken()->isStandardType() || - isRecordTypeWithoutSideEffects(i->type()) || - mSettings->library.detectContainer(i->typeStartToken()) || i->isStlType()) type = Variables::standard; + else { + if (isRecordTypeWithoutSideEffects(i->type()) || mSettings->library.detectContainer(i->typeStartToken())) + type = Variables::standard; + else { + Library::TypeCheck typeCheck = mSettings->library.getTypeCheck("unusedvar", i->typeStartToken()->str()); + if (typeCheck == Library::TypeCheck::check) + type = Variables::standard; + } + } if (type == Variables::none || isPartOfClassStructUnion(i->typeStartToken())) continue; const Token* defValTok = i->nameToken()->next(); diff --git a/test/cfg/qt.cpp b/test/cfg/qt.cpp index 5fcb803e3728..64472f692891 100644 --- a/test/cfg/qt.cpp +++ b/test/cfg/qt.cpp @@ -51,6 +51,17 @@ void unreadVariable_QRegion(const int x, const QRegion::RegionType type, const Q QRegion g{region}; } +void unusedVariable_QPoint_QSize_QRect_QRegion() { // #12529 + // cppcheck-suppress unusedVariable + QPoint pt; + // cppcheck-suppress unusedVariable + QSize sz; + // cppcheck-suppress unusedVariable + QRect rect; + // cppcheck-suppress unusedVariable + QRegion reg; +} + void unreadVariable_QPoint(const QPoint &s) { // cppcheck-suppress unreadVariable