Skip to content

Commit

Permalink
Fix #12529 false negative: unusedVariable with library type (#6157)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github authored Mar 21, 2024
1 parent cd01072 commit e64c368
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 27 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
4 changes: 3 additions & 1 deletion lib/checkunusedvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -713,10 +713,12 @@ void CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(const Scope* const
type = Variables::pointer;
else if (mTokenizer->isC() ||
i->typeEndToken()->isStandardType() ||
i->isStlType() ||
isRecordTypeWithoutSideEffects(i->type()) ||
mSettings->library.detectContainer(i->typeStartToken()) ||
i->isStlType())
mSettings->library.getTypeCheck("unusedvar", i->typeStartToken()->str()) == Library::TypeCheck::check)
type = Variables::standard;

if (type == Variables::none || isPartOfClassStructUnion(i->typeStartToken()))
continue;
const Token* defValTok = i->nameToken()->next();
Expand Down
22 changes: 11 additions & 11 deletions test/cfg/qt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@
#include <QCoreApplication>
#include <QLoggingCategory>
#include <QTest>
#include <QRectF>
#include <QRegion>
#include <QSizeF>
#include <QPointF>
#include <QRect>
#include <QRectF>
#include <QSize>
#include <QSizeF>
#include <QPoint>
#include <QPointF>
#include <QRegion>

#include <cstdio>

void unreadVariable_QRegion(const int x, const QRegion::RegionType type, const QPolygon &polygon, const QBitmap &bm, const QRegion &region, const Qt::FillRule fillRule)
{
// cppcheck-suppress unreadVariable
// cppcheck-suppress unusedVariable
QRegion a;
// cppcheck-suppress unreadVariable
QRegion b{};
Expand All @@ -53,7 +53,7 @@ void unreadVariable_QRegion(const int x, const QRegion::RegionType type, const Q

void unreadVariable_QPoint(const QPoint &s)
{
// cppcheck-suppress unreadVariable
// cppcheck-suppress unusedVariable
QPoint a;
// cppcheck-suppress unreadVariable
QPoint b{};
Expand All @@ -67,7 +67,7 @@ void unreadVariable_QPoint(const QPoint &s)

void unreadVariable_QPointF(const QPointF &s)
{
// cppcheck-suppress unreadVariable
// cppcheck-suppress unusedVariable
QPointF a;
// cppcheck-suppress unreadVariable
QPointF b{};
Expand All @@ -81,7 +81,7 @@ void unreadVariable_QPointF(const QPointF &s)

void unreadVariable_QSizeF(const QSize &s)
{
// cppcheck-suppress unreadVariable
// cppcheck-suppress unusedVariable
QSizeF a;
// cppcheck-suppress unreadVariable
QSizeF b{};
Expand All @@ -95,7 +95,7 @@ void unreadVariable_QSizeF(const QSize &s)

void unreadVariable_QSize(const QSize &s)
{
// cppcheck-suppress unreadVariable
// cppcheck-suppress unusedVariable
QSize a;
// cppcheck-suppress unreadVariable
QSize b{};
Expand All @@ -108,7 +108,7 @@ void unreadVariable_QSize(const QSize &s)
}

void unreadVariable_QRect(const QPoint &topLeft, const QSize &size, const QPoint &bottomRight, const int x) {
// cppcheck-suppress unreadVariable
// cppcheck-suppress unusedVariable
QRect a;
// cppcheck-suppress unreadVariable
QRect b{};
Expand All @@ -123,7 +123,7 @@ void unreadVariable_QRect(const QPoint &topLeft, const QSize &size, const QPoint
}

void unreadVariable_QRectF(const QPointF &topLeft, const QSizeF &size, const QPointF &bottomRight, const QRectF &rect, const qreal x) {
// cppcheck-suppress unreadVariable
// cppcheck-suppress unusedVariable
QRectF a;
// cppcheck-suppress unreadVariable
QRectF b{};
Expand Down
24 changes: 12 additions & 12 deletions test/cfg/wxwidgets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@
#include <wx/position.h>
#include <wx/versioninfo.h>

void unreadVariable_wxAcceleratorEntry()
void unusedVariable_wxAcceleratorEntry()
{
// cppcheck-suppress unreadVariable
// cppcheck-suppress unusedVariable
wxAcceleratorEntry a;
}

void unreadVariable_wxDateSpan(const int x)
{
// cppcheck-suppress unreadVariable
// cppcheck-suppress unusedVariable
wxDateSpan a;
// cppcheck-suppress unreadVariable
wxDateSpan b{x};
Expand All @@ -58,7 +58,7 @@ void unreadVariable_wxDateSpan(const int x)

void unreadVariable_wxTimeSpan(const long x, const wxLongLong y)
{
// cppcheck-suppress unreadVariable
// cppcheck-suppress unusedVariable
wxTimeSpan a;
// cppcheck-suppress unreadVariable
wxTimeSpan b{};
Expand All @@ -80,7 +80,7 @@ void unreadVariable_wxFileType(const wxFileTypeInfo &info)

void unreadVariable_wxPosition(const int x)
{
// cppcheck-suppress unreadVariable
// cppcheck-suppress unusedVariable
wxPosition a;
// cppcheck-suppress unreadVariable
wxPosition b{};
Expand All @@ -90,7 +90,7 @@ void unreadVariable_wxPosition(const int x)

void unreadVariable_wxRegEx(const wxString &expr, const int flags)
{
// cppcheck-suppress unreadVariable
// cppcheck-suppress unusedVariable
wxRegEx a;
// cppcheck-suppress unreadVariable
wxRegEx b{expr};
Expand All @@ -100,7 +100,7 @@ void unreadVariable_wxRegEx(const wxString &expr, const int flags)

void unreadVariable_wxRegion(const wxCoord x, const wxPoint &pt, const wxRect &rect, const wxRegion &region, const wxBitmap &bmp)
{
// cppcheck-suppress unreadVariable
// cppcheck-suppress unusedVariable
wxRegion a;
// cppcheck-suppress unreadVariable
wxRegion b{};
Expand All @@ -118,7 +118,7 @@ void unreadVariable_wxRegion(const wxCoord x, const wxPoint &pt, const wxRect &r

void unreadVariable_wxVersionInfo(const wxString &name, const int major, const int minor, const int micro, const wxString &description, const wxString &copyright)
{
// cppcheck-suppress unreadVariable
// cppcheck-suppress unusedVariable
wxVersionInfo a;
// cppcheck-suppress unreadVariable
wxVersionInfo b(name);
Expand All @@ -136,7 +136,7 @@ void unreadVariable_wxVersionInfo(const wxString &name, const int major, const i

void unreadVariable_wxSize(const wxSize &s)
{
// cppcheck-suppress unreadVariable
// cppcheck-suppress unusedVariable
wxSize a;
// cppcheck-suppress unreadVariable
wxSize b{};
Expand All @@ -150,7 +150,7 @@ void unreadVariable_wxSize(const wxSize &s)

void unreadVariable_wxPoint(const wxRealPoint &rp, const int x, const int y)
{
// cppcheck-suppress unreadVariable
// cppcheck-suppress unusedVariable
wxPoint a;
// cppcheck-suppress unreadVariable
wxPoint b{};
Expand All @@ -168,7 +168,7 @@ void unreadVariable_wxPoint(const wxRealPoint &rp, const int x, const int y)

void unreadVariable_wxRealPoint(const wxPoint &pt, const double x, const double y)
{
// cppcheck-suppress unreadVariable
// cppcheck-suppress unusedVariable
wxRealPoint a;
// cppcheck-suppress unreadVariable
wxRealPoint b{};
Expand All @@ -186,7 +186,7 @@ void unreadVariable_wxRealPoint(const wxPoint &pt, const double x, const double

void unreadVariable_wxRect(const int x, const wxPoint &pt, const wxSize &sz)
{
// cppcheck-suppress unreadVariable
// cppcheck-suppress unusedVariable
wxRect a;
// cppcheck-suppress unreadVariable
wxRect b{};
Expand Down

0 comments on commit e64c368

Please sign in to comment.