Skip to content

Commit e64c368

Browse files
Fix #12529 false negative: unusedVariable with library type (#6157)
1 parent cd01072 commit e64c368

File tree

4 files changed

+29
-27
lines changed

4 files changed

+29
-27
lines changed

cfg/qt.cfg

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5236,12 +5236,12 @@
52365236
<unusedvar>
52375237
<suppress>QApplication</suppress>
52385238
<suppress>QMutexLocker</suppress>
5239-
<check>QRectF</check>
5240-
<check>QSizeF</check>
5241-
<check>QPointF</check>
52425239
<check>QRect</check>
5240+
<check>QRectF</check>
52435241
<check>QSize</check>
5242+
<check>QSizeF</check>
52445243
<check>QPoint</check>
5244+
<check>QPointF</check>
52455245
<check>QRegion</check>
52465246
</unusedvar>
52475247
<operatorEqVarError>

lib/checkunusedvar.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -713,10 +713,12 @@ void CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(const Scope* const
713713
type = Variables::pointer;
714714
else if (mTokenizer->isC() ||
715715
i->typeEndToken()->isStandardType() ||
716+
i->isStlType() ||
716717
isRecordTypeWithoutSideEffects(i->type()) ||
717718
mSettings->library.detectContainer(i->typeStartToken()) ||
718-
i->isStlType())
719+
mSettings->library.getTypeCheck("unusedvar", i->typeStartToken()->str()) == Library::TypeCheck::check)
719720
type = Variables::standard;
721+
720722
if (type == Variables::none || isPartOfClassStructUnion(i->typeStartToken()))
721723
continue;
722724
const Token* defValTok = i->nameToken()->next();

test/cfg/qt.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,19 @@
2323
#include <QCoreApplication>
2424
#include <QLoggingCategory>
2525
#include <QTest>
26-
#include <QRectF>
27-
#include <QRegion>
28-
#include <QSizeF>
29-
#include <QPointF>
3026
#include <QRect>
27+
#include <QRectF>
3128
#include <QSize>
29+
#include <QSizeF>
3230
#include <QPoint>
31+
#include <QPointF>
32+
#include <QRegion>
3333

3434
#include <cstdio>
3535

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

5454
void unreadVariable_QPoint(const QPoint &s)
5555
{
56-
// cppcheck-suppress unreadVariable
56+
// cppcheck-suppress unusedVariable
5757
QPoint a;
5858
// cppcheck-suppress unreadVariable
5959
QPoint b{};
@@ -67,7 +67,7 @@ void unreadVariable_QPoint(const QPoint &s)
6767

6868
void unreadVariable_QPointF(const QPointF &s)
6969
{
70-
// cppcheck-suppress unreadVariable
70+
// cppcheck-suppress unusedVariable
7171
QPointF a;
7272
// cppcheck-suppress unreadVariable
7373
QPointF b{};
@@ -81,7 +81,7 @@ void unreadVariable_QPointF(const QPointF &s)
8181

8282
void unreadVariable_QSizeF(const QSize &s)
8383
{
84-
// cppcheck-suppress unreadVariable
84+
// cppcheck-suppress unusedVariable
8585
QSizeF a;
8686
// cppcheck-suppress unreadVariable
8787
QSizeF b{};
@@ -95,7 +95,7 @@ void unreadVariable_QSizeF(const QSize &s)
9595

9696
void unreadVariable_QSize(const QSize &s)
9797
{
98-
// cppcheck-suppress unreadVariable
98+
// cppcheck-suppress unusedVariable
9999
QSize a;
100100
// cppcheck-suppress unreadVariable
101101
QSize b{};
@@ -108,7 +108,7 @@ void unreadVariable_QSize(const QSize &s)
108108
}
109109

110110
void unreadVariable_QRect(const QPoint &topLeft, const QSize &size, const QPoint &bottomRight, const int x) {
111-
// cppcheck-suppress unreadVariable
111+
// cppcheck-suppress unusedVariable
112112
QRect a;
113113
// cppcheck-suppress unreadVariable
114114
QRect b{};
@@ -123,7 +123,7 @@ void unreadVariable_QRect(const QPoint &topLeft, const QSize &size, const QPoint
123123
}
124124

125125
void unreadVariable_QRectF(const QPointF &topLeft, const QSizeF &size, const QPointF &bottomRight, const QRectF &rect, const qreal x) {
126-
// cppcheck-suppress unreadVariable
126+
// cppcheck-suppress unusedVariable
127127
QRectF a;
128128
// cppcheck-suppress unreadVariable
129129
QRectF b{};

test/cfg/wxwidgets.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@
3636
#include <wx/position.h>
3737
#include <wx/versioninfo.h>
3838

39-
void unreadVariable_wxAcceleratorEntry()
39+
void unusedVariable_wxAcceleratorEntry()
4040
{
41-
// cppcheck-suppress unreadVariable
41+
// cppcheck-suppress unusedVariable
4242
wxAcceleratorEntry a;
4343
}
4444

4545
void unreadVariable_wxDateSpan(const int x)
4646
{
47-
// cppcheck-suppress unreadVariable
47+
// cppcheck-suppress unusedVariable
4848
wxDateSpan a;
4949
// cppcheck-suppress unreadVariable
5050
wxDateSpan b{x};
@@ -58,7 +58,7 @@ void unreadVariable_wxDateSpan(const int x)
5858

5959
void unreadVariable_wxTimeSpan(const long x, const wxLongLong y)
6060
{
61-
// cppcheck-suppress unreadVariable
61+
// cppcheck-suppress unusedVariable
6262
wxTimeSpan a;
6363
// cppcheck-suppress unreadVariable
6464
wxTimeSpan b{};
@@ -80,7 +80,7 @@ void unreadVariable_wxFileType(const wxFileTypeInfo &info)
8080

8181
void unreadVariable_wxPosition(const int x)
8282
{
83-
// cppcheck-suppress unreadVariable
83+
// cppcheck-suppress unusedVariable
8484
wxPosition a;
8585
// cppcheck-suppress unreadVariable
8686
wxPosition b{};
@@ -90,7 +90,7 @@ void unreadVariable_wxPosition(const int x)
9090

9191
void unreadVariable_wxRegEx(const wxString &expr, const int flags)
9292
{
93-
// cppcheck-suppress unreadVariable
93+
// cppcheck-suppress unusedVariable
9494
wxRegEx a;
9595
// cppcheck-suppress unreadVariable
9696
wxRegEx b{expr};
@@ -100,7 +100,7 @@ void unreadVariable_wxRegEx(const wxString &expr, const int flags)
100100

101101
void unreadVariable_wxRegion(const wxCoord x, const wxPoint &pt, const wxRect &rect, const wxRegion &region, const wxBitmap &bmp)
102102
{
103-
// cppcheck-suppress unreadVariable
103+
// cppcheck-suppress unusedVariable
104104
wxRegion a;
105105
// cppcheck-suppress unreadVariable
106106
wxRegion b{};
@@ -118,7 +118,7 @@ void unreadVariable_wxRegion(const wxCoord x, const wxPoint &pt, const wxRect &r
118118

119119
void unreadVariable_wxVersionInfo(const wxString &name, const int major, const int minor, const int micro, const wxString &description, const wxString &copyright)
120120
{
121-
// cppcheck-suppress unreadVariable
121+
// cppcheck-suppress unusedVariable
122122
wxVersionInfo a;
123123
// cppcheck-suppress unreadVariable
124124
wxVersionInfo b(name);
@@ -136,7 +136,7 @@ void unreadVariable_wxVersionInfo(const wxString &name, const int major, const i
136136

137137
void unreadVariable_wxSize(const wxSize &s)
138138
{
139-
// cppcheck-suppress unreadVariable
139+
// cppcheck-suppress unusedVariable
140140
wxSize a;
141141
// cppcheck-suppress unreadVariable
142142
wxSize b{};
@@ -150,7 +150,7 @@ void unreadVariable_wxSize(const wxSize &s)
150150

151151
void unreadVariable_wxPoint(const wxRealPoint &rp, const int x, const int y)
152152
{
153-
// cppcheck-suppress unreadVariable
153+
// cppcheck-suppress unusedVariable
154154
wxPoint a;
155155
// cppcheck-suppress unreadVariable
156156
wxPoint b{};
@@ -168,7 +168,7 @@ void unreadVariable_wxPoint(const wxRealPoint &rp, const int x, const int y)
168168

169169
void unreadVariable_wxRealPoint(const wxPoint &pt, const double x, const double y)
170170
{
171-
// cppcheck-suppress unreadVariable
171+
// cppcheck-suppress unusedVariable
172172
wxRealPoint a;
173173
// cppcheck-suppress unreadVariable
174174
wxRealPoint b{};
@@ -186,7 +186,7 @@ void unreadVariable_wxRealPoint(const wxPoint &pt, const double x, const double
186186

187187
void unreadVariable_wxRect(const int x, const wxPoint &pt, const wxSize &sz)
188188
{
189-
// cppcheck-suppress unreadVariable
189+
// cppcheck-suppress unusedVariable
190190
wxRect a;
191191
// cppcheck-suppress unreadVariable
192192
wxRect b{};

0 commit comments

Comments
 (0)