Skip to content

Commit 6edb2e7

Browse files
author
Daniel Marjamäki
committed
Refactoring: Removed Severity::possibleStyle
1 parent 5fe2a56 commit 6edb2e7

11 files changed

Lines changed: 47 additions & 108 deletions

‎lib/check.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ class Check
101101
std::list<const Token *> callstack;
102102
if (tok)
103103
callstack.push_back(tok);
104-
else if (severity == Severity::possibleError || severity == Severity::possibleStyle)
104+
else if (severity == Severity::possibleError)
105105
return; // don't list inconclusive checks in the --errorlist output
106106
reportError(callstack, severity, id, msg);
107107
}

‎lib/checkclass.cpp‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -582,8 +582,8 @@ void CheckClass::checkConstructors(const Token *tok1, const std::string &funcnam
582582
if (classNameUsed)
583583
operatorEqVarError(constructor_token, className, var->name);
584584
}
585-
else if (!var->isStatic)
586-
uninitVarError(constructor_token, className, var->name, hasPrivateConstructor);
585+
else if (!hasPrivateConstructor && !var->isStatic)
586+
uninitVarError(constructor_token, className, var->name);
587587
}
588588

589589
for (Var *var = varlist; var; var = var->next)
@@ -1986,9 +1986,9 @@ void CheckClass::noConstructorError(const Token *tok, const std::string &classna
19861986
reportError(tok, Severity::style, "noConstructor", "The " + std::string(isStruct ? "struct" : "class") + " '" + classname + "' has no constructor. Member variables not initialized.");
19871987
}
19881988

1989-
void CheckClass::uninitVarError(const Token *tok, const std::string &classname, const std::string &varname, bool hasPrivateConstructor)
1989+
void CheckClass::uninitVarError(const Token *tok, const std::string &classname, const std::string &varname)
19901990
{
1991-
reportError(tok, hasPrivateConstructor ? Severity::possibleStyle : Severity::style, "uninitVar", "Member variable not initialized in the constructor '" + classname + "::" + varname + "'");
1991+
reportError(tok, Severity::style, "uninitVar", "Member variable not initialized in the constructor '" + classname + "::" + varname + "'");
19921992
}
19931993

19941994
void CheckClass::operatorEqVarError(const Token *tok, const std::string &classname, const std::string &varname)

‎lib/checkclass.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ class CheckClass : public Check
180180

181181
// Reporting errors..
182182
void noConstructorError(const Token *tok, const std::string &classname, bool isStruct);
183-
void uninitVarError(const Token *tok, const std::string &classname, const std::string &varname, bool hasPrivateConstructor);
183+
void uninitVarError(const Token *tok, const std::string &classname, const std::string &varname);
184184
void operatorEqVarError(const Token *tok, const std::string &classname, const std::string &varname);
185185
void unusedPrivateFunctionError(const Token *tok, const std::string &classname, const std::string &funcname);
186186
void memsetClassError(const Token *tok, const std::string &memfunc);
@@ -197,7 +197,7 @@ class CheckClass : public Check
197197
void getErrorMessages()
198198
{
199199
noConstructorError(0, "classname", false);
200-
uninitVarError(0, "classname", "varname", false);
200+
uninitVarError(0, "classname", "varname");
201201
operatorEqVarError(0, "classname", "");
202202
unusedPrivateFunctionError(0, "classname", "funcname");
203203
memsetClassError(0, "memfunc");

‎lib/checkother.cpp‎

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ void CheckOther::invalidFunctionUsage()
356356

357357
void CheckOther::checkUnsignedDivision()
358358
{
359-
if (!_settings->inconclusive || !_settings->_checkCodingStyle)
359+
if (!_settings->_checkCodingStyle)
360360
return;
361361

362362
// Check for "ivar / uvar" and "uvar / ivar"
@@ -371,24 +371,9 @@ void CheckOther::checkUnsignedDivision()
371371
varsign[tok->tokAt(2)->varId()] = 's';
372372
}
373373

374-
else if (!Token::Match(tok, "[).]") &&
375-
Token::Match(tok->next(), "%var% / %var%") &&
376-
tok->tokAt(1)->varId() != 0 &&
377-
tok->tokAt(3)->varId() != 0)
378-
{
379-
char sign1 = varsign[tok->tokAt(1)->varId()];
380-
char sign2 = varsign[tok->tokAt(3)->varId()];
381-
382-
if (sign1 && sign2 && sign1 != sign2)
383-
{
384-
// One of the operands are signed, the other is unsigned..
385-
udivWarning(tok->next());
386-
}
387-
}
388-
389374
else if (!Token::Match(tok, "[).]") && Token::Match(tok->next(), "%var% / %num%"))
390375
{
391-
if (tok->strAt(3)[0] == '-' && ErrorLogger::udivError())
376+
if (tok->strAt(3)[0] == '-')
392377
{
393378
char sign1 = varsign[tok->tokAt(1)->varId()];
394379
if (sign1 == 'u')
@@ -400,7 +385,7 @@ void CheckOther::checkUnsignedDivision()
400385

401386
else if (Token::Match(tok, "[([=*/+-,] %num% / %var%"))
402387
{
403-
if (tok->strAt(1)[0] == '-' && ErrorLogger::udivError())
388+
if (tok->strAt(1)[0] == '-')
404389
{
405390
char sign2 = varsign[tok->tokAt(3)->varId()];
406391
if (sign2 == 'u')
@@ -3518,11 +3503,6 @@ void CheckOther::udivError(const Token *tok)
35183503
reportError(tok, Severity::error, "udivError", "Unsigned division. The result will be wrong.");
35193504
}
35203505

3521-
void CheckOther::udivWarning(const Token *tok)
3522-
{
3523-
reportError(tok, Severity::possibleStyle, "udivWarning", "Division with signed and unsigned operators");
3524-
}
3525-
35263506
void CheckOther::unusedStructMemberError(const Token *tok, const std::string &structname, const std::string &varname)
35273507
{
35283508
reportError(tok, Severity::style, "unusedStructMember", "struct or union member '" + structname + "::" + varname + "' is never used");
@@ -3614,7 +3594,7 @@ void CheckOther::mathfunctionCallError(const Token *tok, const unsigned int numP
36143594
void CheckOther::postIncrementError(const Token *tok, const std::string &var_name, const bool isIncrement)
36153595
{
36163596
std::string type = (isIncrement ? "Incrementing" : "Decrementing");
3617-
reportError(tok, Severity::possibleStyle, "postIncrementDecrement", ("Pre-" + type + " variable '" + var_name + "' is preferred to Post-" + type));
3597+
reportError(tok, Severity::style, "postIncrementDecrement", ("Pre-" + type + " variable '" + var_name + "' is preferred to Post-" + type));
36183598
}
36193599

36203600
void CheckOther::emptyStringTestError(const Token *tok, const std::string &var_name, const bool isTestForEmpty)

‎lib/checkother.h‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,6 @@ class CheckOther : public Check
174174
void dangerousUsageStrtolError(const Token *tok);
175175
void sprintfOverlappingDataError(const Token *tok, const std::string &varname);
176176
void udivError(const Token *tok);
177-
void udivWarning(const Token *tok);
178177
void unusedStructMemberError(const Token *tok, const std::string &structname, const std::string &varname);
179178
void passedByValueError(const Token *tok, const std::string &parname);
180179
void constStatementError(const Token *tok, const std::string &type);
@@ -213,7 +212,6 @@ class CheckOther : public Check
213212
redundantIfDelete0Error(0);
214213
redundantIfRemoveError(0);
215214
dangerousUsageStrtolError(0);
216-
udivWarning(0);
217215
unusedStructMemberError(0, "structname", "variable");
218216
passedByValueError(0, "parametername");
219217
constStatementError(0, "type");

‎lib/checkstl.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -688,5 +688,5 @@ void CheckStl::sizeError(const Token *tok)
688688
{
689689
const std::string varname(tok ? tok->str().c_str() : "list");
690690
const bool verbose(_settings ? _settings->_verbose : true);
691-
reportError(tok, Severity::possibleStyle, "stlSize", "Use " + varname + ".empty() instead of " + varname + ".size() to guarantee fast code." + (verbose ? " size() can take linear time but empty() is guaranteed to take constant time." : ""));
691+
reportError(tok, Severity::style, "stlSize", "Use " + varname + ".empty() instead of " + varname + ".size() to guarantee fast code." + (verbose ? " size() can take linear time but empty() is guaranteed to take constant time." : ""));
692692
}

‎lib/errorlogger.h‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ class ErrorLogger
322322
class Severity
323323
{
324324
public:
325-
enum e { error, style, possibleError, possibleStyle };
325+
enum e { error, style, possibleError };
326326
static std::string stringify(e severity)
327327
{
328328
switch (severity)
@@ -333,8 +333,6 @@ class Severity
333333
return "style";
334334
case possibleError:
335335
return "possible error";
336-
case possibleStyle:
337-
return "possible style";
338336
};
339337
return "???";
340338
}

‎test/testclass.cpp‎

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1762,8 +1762,7 @@ class TestClass : public TestFixture
17621762
" int foo;\n"
17631763
" Foo() { }\n"
17641764
"};\n");
1765-
1766-
ASSERT_EQUALS("[test.cpp:3]: (possible style) Member variable not initialized in the constructor 'Foo::foo'\n", errout.str());
1765+
ASSERT_EQUALS("", errout.str());
17671766
}
17681767

17691768
void privateCtor2()
@@ -1777,13 +1776,11 @@ class TestClass : public TestFixture
17771776
" Foo(int _i) { }\n"
17781777
"};\n");
17791778

1780-
// actual results - "possible style" for both messages
1781-
ASSERT_EQUALS("[test.cpp:5]: (possible style) Member variable not initialized in the constructor 'Foo::foo'\n"
1782-
"[test.cpp:7]: (possible style) Member variable not initialized in the constructor 'Foo::foo'\n", errout.str());
1779+
// actual results
1780+
ASSERT_EQUALS("", errout.str());
17831781

1784-
// wanted results - "style" for the public constructor
1785-
TODO_ASSERT_EQUALS("[test.cpp:5]: (possible style) Member variable not initialized in the constructor 'Foo::foo'\n"
1786-
"[test.cpp:7]: (style) Member variable not initialized in the constructor 'Foo::foo'\n", errout.str());
1782+
// wanted results - warning for the public constructor
1783+
TODO_ASSERT_EQUALS("[test.cpp:7]: (style) Member variable not initialized in the constructor 'Foo::foo'\n", errout.str());
17871784
}
17881785

17891786

‎test/testdivision.cpp‎

Lines changed: 15 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class TestDivision : public TestFixture
3636
{ }
3737

3838
private:
39-
void check(const char code[], bool style = true, bool all = true)
39+
void check(const char code[], bool style = true)
4040
{
4141
// Tokenize..
4242
Tokenizer tokenizer;
@@ -47,7 +47,6 @@ class TestDivision : public TestFixture
4747
errout.str("");
4848

4949
Settings settings;
50-
settings.inconclusive = all;
5150
settings._checkCodingStyle = style;
5251

5352
// Check for unsigned divisions..
@@ -59,7 +58,6 @@ class TestDivision : public TestFixture
5958
{
6059
TEST_CASE(division1);
6160
TEST_CASE(division2);
62-
TEST_CASE(division3);
6361
TEST_CASE(division4);
6462
TEST_CASE(division5);
6563
TEST_CASE(division6);
@@ -76,7 +74,8 @@ class TestDivision : public TestFixture
7674
" unsigned int uvar = 2;\n"
7775
" return ivar / uvar;\n"
7876
"}\n");
79-
ASSERT_EQUALS("[test.cpp:5]: (possible style) Division with signed and unsigned operators\n", errout.str());
77+
TODO_ASSERT_EQUALS("[test.cpp:5]: (style) Division with signed and unsigned operators\n", errout.str());
78+
ASSERT_EQUALS("", errout.str());
8079
}
8180

8281
void division2()
@@ -87,20 +86,8 @@ class TestDivision : public TestFixture
8786
" unsigned int uvar = 2;\n"
8887
" return uvar / ivar;\n"
8988
"}\n");
90-
ASSERT_EQUALS("[test.cpp:5]: (possible style) Division with signed and unsigned operators\n", errout.str());
91-
}
92-
93-
void division3()
94-
{
95-
check("typedef int s32;\n"
96-
"typedef unsigned int u32;\n"
97-
"void f()\n"
98-
"{\n"
99-
" s32 ivar = -2;\n"
100-
" u32 uvar = 2;\n"
101-
" return uvar / ivar;\n"
102-
"}\n");
103-
ASSERT_EQUALS("[test.cpp:7]: (possible style) Division with signed and unsigned operators\n", errout.str());
89+
TODO_ASSERT_EQUALS("[test.cpp:5]: (style) Division with signed and unsigned operators\n", errout.str());
90+
ASSERT_EQUALS("", errout.str());
10491
}
10592

10693
void division4()
@@ -155,8 +142,7 @@ class TestDivision : public TestFixture
155142
check("void foo()\n"
156143
"{\n"
157144
" unsigned int val = 32;\n"
158-
" int i = -96 / val; }\n"
159-
);
145+
" int i = -96 / val; }\n");
160146
ASSERT_EQUALS("[test.cpp:4]: (error) Unsigned division. The result will be wrong.\n", errout.str());
161147
}
162148

@@ -169,35 +155,26 @@ class TestDivision : public TestFixture
169155
" unsigned int a;\n"
170156
" unsigned int c = a / b;\n"
171157
" }\n"
172-
"}\n", false, true);
158+
"}\n", true);
173159
ASSERT_EQUALS("", errout.str());
174160

175161
check("void foo(int b)\n"
176162
"{\n"
177-
" if (b > 0)\n"
163+
" if (b < 0)\n"
178164
" {\n"
179165
" unsigned int a;\n"
180166
" unsigned int c = a / b;\n"
181167
" }\n"
182-
"}\n", true, false);
168+
"}\n", true);
183169
ASSERT_EQUALS("", errout.str());
184-
185-
check("void foo(int b)\n"
186-
"{\n"
187-
" if (b > 0)\n"
188-
" {\n"
189-
" unsigned int a;\n"
190-
" unsigned int c = a / b;\n"
191-
" }\n"
192-
"}\n", true, true);
193-
ASSERT_EQUALS("[test.cpp:6]: (possible style) Division with signed and unsigned operators\n", errout.str());
170+
TODO_ASSERT_EQUALS("unsigned division", errout.str());
194171

195172
check("void a(int i) { }\n"
196173
"int foo( unsigned int sz )\n"
197174
"{\n"
198175
" register unsigned int i=1;\n"
199176
" return i/sz;\n"
200-
"}\n", true, true);
177+
"}\n", true);
201178
ASSERT_EQUALS("", errout.str());
202179
}
203180

@@ -209,28 +186,17 @@ class TestDivision : public TestFixture
209186
" unsigned long uvar = 2;\n"
210187
" return ivar / uvar;\n"
211188
"}\n");
212-
ASSERT_EQUALS("[test.cpp:5]: (possible style) Division with signed and unsigned operators\n", errout.str());
189+
ASSERT_EQUALS("", errout.str());
190+
TODO_ASSERT_EQUALS("unsigned division", errout.str());
213191

214192
check("void f()\n"
215193
"{\n"
216194
" int ivar = -2;\n"
217195
" unsigned long long uvar = 2;\n"
218196
" return ivar / uvar;\n"
219197
"}\n");
220-
ASSERT_EQUALS("[test.cpp:5]: (possible style) Division with signed and unsigned operators\n", errout.str());
221-
222-
check("template<class A, class B> class C\n"
223-
"{\n"
224-
" A a;\n"
225-
" B b;\n"
226-
" void foo() { a / b; }\n"
227-
"};\n"
228-
"C<int, unsigned int> c1;\n"
229-
"C<int, unsigned long> c2;\n"
230-
"C<int, unsigned long long> c3;\n");
231-
ASSERT_EQUALS("[test.cpp:5]: (possible style) Division with signed and unsigned operators\n"
232-
"[test.cpp:5]: (possible style) Division with signed and unsigned operators\n"
233-
"[test.cpp:5]: (possible style) Division with signed and unsigned operators\n", errout.str());
198+
ASSERT_EQUALS("", errout.str());
199+
TODO_ASSERT_EQUALS("unsigned division", errout.str());
234200
}
235201
};
236202

0 commit comments

Comments
 (0)