Skip to content

Commit

Permalink
Fix #12529 false negative: unreadVariable with library type
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github committed Mar 19, 2024
1 parent e2081e8 commit 3172f54
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
6 changes: 3 additions & 3 deletions cfg/qt.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -5236,12 +5236,12 @@
<unusedvar>
<suppress>QApplication</suppress>
<suppress>QMutexLocker</suppress>
<check>QRectF</check>
<check>QSizeF</check>
<check>QPointF</check>
<check>QRect</check>
<check>QRectF</check>
<check>QSize</check>
<check>QSizeF</check>
<check>QPoint</check>
<check>QPointF</check>
<check>QRegion</check>
</unusedvar>
<operatorEqVarError>
Expand Down
11 changes: 9 additions & 2 deletions lib/checkunusedvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
11 changes: 11 additions & 0 deletions test/cfg/qt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3172f54

Please sign in to comment.