Refactoring: Removed Severity::possibleStyle
This commit is contained in:
parent
5fe2a56b41
commit
6edb2e77b4
|
@ -101,7 +101,7 @@ protected:
|
||||||
std::list<const Token *> callstack;
|
std::list<const Token *> callstack;
|
||||||
if (tok)
|
if (tok)
|
||||||
callstack.push_back(tok);
|
callstack.push_back(tok);
|
||||||
else if (severity == Severity::possibleError || severity == Severity::possibleStyle)
|
else if (severity == Severity::possibleError)
|
||||||
return; // don't list inconclusive checks in the --errorlist output
|
return; // don't list inconclusive checks in the --errorlist output
|
||||||
reportError(callstack, severity, id, msg);
|
reportError(callstack, severity, id, msg);
|
||||||
}
|
}
|
||||||
|
|
|
@ -582,8 +582,8 @@ void CheckClass::checkConstructors(const Token *tok1, const std::string &funcnam
|
||||||
if (classNameUsed)
|
if (classNameUsed)
|
||||||
operatorEqVarError(constructor_token, className, var->name);
|
operatorEqVarError(constructor_token, className, var->name);
|
||||||
}
|
}
|
||||||
else if (!var->isStatic)
|
else if (!hasPrivateConstructor && !var->isStatic)
|
||||||
uninitVarError(constructor_token, className, var->name, hasPrivateConstructor);
|
uninitVarError(constructor_token, className, var->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Var *var = varlist; var; var = var->next)
|
for (Var *var = varlist; var; var = var->next)
|
||||||
|
@ -1986,9 +1986,9 @@ void CheckClass::noConstructorError(const Token *tok, const std::string &classna
|
||||||
reportError(tok, Severity::style, "noConstructor", "The " + std::string(isStruct ? "struct" : "class") + " '" + classname + "' has no constructor. Member variables not initialized.");
|
reportError(tok, Severity::style, "noConstructor", "The " + std::string(isStruct ? "struct" : "class") + " '" + classname + "' has no constructor. Member variables not initialized.");
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckClass::uninitVarError(const Token *tok, const std::string &classname, const std::string &varname, bool hasPrivateConstructor)
|
void CheckClass::uninitVarError(const Token *tok, const std::string &classname, const std::string &varname)
|
||||||
{
|
{
|
||||||
reportError(tok, hasPrivateConstructor ? Severity::possibleStyle : Severity::style, "uninitVar", "Member variable not initialized in the constructor '" + classname + "::" + varname + "'");
|
reportError(tok, Severity::style, "uninitVar", "Member variable not initialized in the constructor '" + classname + "::" + varname + "'");
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckClass::operatorEqVarError(const Token *tok, const std::string &classname, const std::string &varname)
|
void CheckClass::operatorEqVarError(const Token *tok, const std::string &classname, const std::string &varname)
|
||||||
|
|
|
@ -180,7 +180,7 @@ private:
|
||||||
|
|
||||||
// Reporting errors..
|
// Reporting errors..
|
||||||
void noConstructorError(const Token *tok, const std::string &classname, bool isStruct);
|
void noConstructorError(const Token *tok, const std::string &classname, bool isStruct);
|
||||||
void uninitVarError(const Token *tok, const std::string &classname, const std::string &varname, bool hasPrivateConstructor);
|
void uninitVarError(const Token *tok, const std::string &classname, const std::string &varname);
|
||||||
void operatorEqVarError(const Token *tok, const std::string &classname, const std::string &varname);
|
void operatorEqVarError(const Token *tok, const std::string &classname, const std::string &varname);
|
||||||
void unusedPrivateFunctionError(const Token *tok, const std::string &classname, const std::string &funcname);
|
void unusedPrivateFunctionError(const Token *tok, const std::string &classname, const std::string &funcname);
|
||||||
void memsetClassError(const Token *tok, const std::string &memfunc);
|
void memsetClassError(const Token *tok, const std::string &memfunc);
|
||||||
|
@ -197,7 +197,7 @@ private:
|
||||||
void getErrorMessages()
|
void getErrorMessages()
|
||||||
{
|
{
|
||||||
noConstructorError(0, "classname", false);
|
noConstructorError(0, "classname", false);
|
||||||
uninitVarError(0, "classname", "varname", false);
|
uninitVarError(0, "classname", "varname");
|
||||||
operatorEqVarError(0, "classname", "");
|
operatorEqVarError(0, "classname", "");
|
||||||
unusedPrivateFunctionError(0, "classname", "funcname");
|
unusedPrivateFunctionError(0, "classname", "funcname");
|
||||||
memsetClassError(0, "memfunc");
|
memsetClassError(0, "memfunc");
|
||||||
|
|
|
@ -356,7 +356,7 @@ void CheckOther::invalidFunctionUsage()
|
||||||
|
|
||||||
void CheckOther::checkUnsignedDivision()
|
void CheckOther::checkUnsignedDivision()
|
||||||
{
|
{
|
||||||
if (!_settings->inconclusive || !_settings->_checkCodingStyle)
|
if (!_settings->_checkCodingStyle)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Check for "ivar / uvar" and "uvar / ivar"
|
// Check for "ivar / uvar" and "uvar / ivar"
|
||||||
|
@ -371,24 +371,9 @@ void CheckOther::checkUnsignedDivision()
|
||||||
varsign[tok->tokAt(2)->varId()] = 's';
|
varsign[tok->tokAt(2)->varId()] = 's';
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (!Token::Match(tok, "[).]") &&
|
|
||||||
Token::Match(tok->next(), "%var% / %var%") &&
|
|
||||||
tok->tokAt(1)->varId() != 0 &&
|
|
||||||
tok->tokAt(3)->varId() != 0)
|
|
||||||
{
|
|
||||||
char sign1 = varsign[tok->tokAt(1)->varId()];
|
|
||||||
char sign2 = varsign[tok->tokAt(3)->varId()];
|
|
||||||
|
|
||||||
if (sign1 && sign2 && sign1 != sign2)
|
|
||||||
{
|
|
||||||
// One of the operands are signed, the other is unsigned..
|
|
||||||
udivWarning(tok->next());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (!Token::Match(tok, "[).]") && Token::Match(tok->next(), "%var% / %num%"))
|
else if (!Token::Match(tok, "[).]") && Token::Match(tok->next(), "%var% / %num%"))
|
||||||
{
|
{
|
||||||
if (tok->strAt(3)[0] == '-' && ErrorLogger::udivError())
|
if (tok->strAt(3)[0] == '-')
|
||||||
{
|
{
|
||||||
char sign1 = varsign[tok->tokAt(1)->varId()];
|
char sign1 = varsign[tok->tokAt(1)->varId()];
|
||||||
if (sign1 == 'u')
|
if (sign1 == 'u')
|
||||||
|
@ -400,7 +385,7 @@ void CheckOther::checkUnsignedDivision()
|
||||||
|
|
||||||
else if (Token::Match(tok, "[([=*/+-,] %num% / %var%"))
|
else if (Token::Match(tok, "[([=*/+-,] %num% / %var%"))
|
||||||
{
|
{
|
||||||
if (tok->strAt(1)[0] == '-' && ErrorLogger::udivError())
|
if (tok->strAt(1)[0] == '-')
|
||||||
{
|
{
|
||||||
char sign2 = varsign[tok->tokAt(3)->varId()];
|
char sign2 = varsign[tok->tokAt(3)->varId()];
|
||||||
if (sign2 == 'u')
|
if (sign2 == 'u')
|
||||||
|
@ -3518,11 +3503,6 @@ void CheckOther::udivError(const Token *tok)
|
||||||
reportError(tok, Severity::error, "udivError", "Unsigned division. The result will be wrong.");
|
reportError(tok, Severity::error, "udivError", "Unsigned division. The result will be wrong.");
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckOther::udivWarning(const Token *tok)
|
|
||||||
{
|
|
||||||
reportError(tok, Severity::possibleStyle, "udivWarning", "Division with signed and unsigned operators");
|
|
||||||
}
|
|
||||||
|
|
||||||
void CheckOther::unusedStructMemberError(const Token *tok, const std::string &structname, const std::string &varname)
|
void CheckOther::unusedStructMemberError(const Token *tok, const std::string &structname, const std::string &varname)
|
||||||
{
|
{
|
||||||
reportError(tok, Severity::style, "unusedStructMember", "struct or union member '" + structname + "::" + varname + "' is never used");
|
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
|
||||||
void CheckOther::postIncrementError(const Token *tok, const std::string &var_name, const bool isIncrement)
|
void CheckOther::postIncrementError(const Token *tok, const std::string &var_name, const bool isIncrement)
|
||||||
{
|
{
|
||||||
std::string type = (isIncrement ? "Incrementing" : "Decrementing");
|
std::string type = (isIncrement ? "Incrementing" : "Decrementing");
|
||||||
reportError(tok, Severity::possibleStyle, "postIncrementDecrement", ("Pre-" + type + " variable '" + var_name + "' is preferred to Post-" + type));
|
reportError(tok, Severity::style, "postIncrementDecrement", ("Pre-" + type + " variable '" + var_name + "' is preferred to Post-" + type));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckOther::emptyStringTestError(const Token *tok, const std::string &var_name, const bool isTestForEmpty)
|
void CheckOther::emptyStringTestError(const Token *tok, const std::string &var_name, const bool isTestForEmpty)
|
||||||
|
|
|
@ -174,7 +174,6 @@ public:
|
||||||
void dangerousUsageStrtolError(const Token *tok);
|
void dangerousUsageStrtolError(const Token *tok);
|
||||||
void sprintfOverlappingDataError(const Token *tok, const std::string &varname);
|
void sprintfOverlappingDataError(const Token *tok, const std::string &varname);
|
||||||
void udivError(const Token *tok);
|
void udivError(const Token *tok);
|
||||||
void udivWarning(const Token *tok);
|
|
||||||
void unusedStructMemberError(const Token *tok, const std::string &structname, const std::string &varname);
|
void unusedStructMemberError(const Token *tok, const std::string &structname, const std::string &varname);
|
||||||
void passedByValueError(const Token *tok, const std::string &parname);
|
void passedByValueError(const Token *tok, const std::string &parname);
|
||||||
void constStatementError(const Token *tok, const std::string &type);
|
void constStatementError(const Token *tok, const std::string &type);
|
||||||
|
@ -213,7 +212,6 @@ public:
|
||||||
redundantIfDelete0Error(0);
|
redundantIfDelete0Error(0);
|
||||||
redundantIfRemoveError(0);
|
redundantIfRemoveError(0);
|
||||||
dangerousUsageStrtolError(0);
|
dangerousUsageStrtolError(0);
|
||||||
udivWarning(0);
|
|
||||||
unusedStructMemberError(0, "structname", "variable");
|
unusedStructMemberError(0, "structname", "variable");
|
||||||
passedByValueError(0, "parametername");
|
passedByValueError(0, "parametername");
|
||||||
constStatementError(0, "type");
|
constStatementError(0, "type");
|
||||||
|
|
|
@ -688,5 +688,5 @@ void CheckStl::sizeError(const Token *tok)
|
||||||
{
|
{
|
||||||
const std::string varname(tok ? tok->str().c_str() : "list");
|
const std::string varname(tok ? tok->str().c_str() : "list");
|
||||||
const bool verbose(_settings ? _settings->_verbose : true);
|
const bool verbose(_settings ? _settings->_verbose : true);
|
||||||
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." : ""));
|
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." : ""));
|
||||||
}
|
}
|
||||||
|
|
|
@ -322,7 +322,7 @@ private:
|
||||||
class Severity
|
class Severity
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
enum e { error, style, possibleError, possibleStyle };
|
enum e { error, style, possibleError };
|
||||||
static std::string stringify(e severity)
|
static std::string stringify(e severity)
|
||||||
{
|
{
|
||||||
switch (severity)
|
switch (severity)
|
||||||
|
@ -333,8 +333,6 @@ public:
|
||||||
return "style";
|
return "style";
|
||||||
case possibleError:
|
case possibleError:
|
||||||
return "possible error";
|
return "possible error";
|
||||||
case possibleStyle:
|
|
||||||
return "possible style";
|
|
||||||
};
|
};
|
||||||
return "???";
|
return "???";
|
||||||
}
|
}
|
||||||
|
|
|
@ -1762,8 +1762,7 @@ private:
|
||||||
" int foo;\n"
|
" int foo;\n"
|
||||||
" Foo() { }\n"
|
" Foo() { }\n"
|
||||||
"};\n");
|
"};\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
ASSERT_EQUALS("[test.cpp:3]: (possible style) Member variable not initialized in the constructor 'Foo::foo'\n", errout.str());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void privateCtor2()
|
void privateCtor2()
|
||||||
|
@ -1777,13 +1776,11 @@ private:
|
||||||
" Foo(int _i) { }\n"
|
" Foo(int _i) { }\n"
|
||||||
"};\n");
|
"};\n");
|
||||||
|
|
||||||
// actual results - "possible style" for both messages
|
// actual results
|
||||||
ASSERT_EQUALS("[test.cpp:5]: (possible style) Member variable not initialized in the constructor 'Foo::foo'\n"
|
ASSERT_EQUALS("", errout.str());
|
||||||
"[test.cpp:7]: (possible style) Member variable not initialized in the constructor 'Foo::foo'\n", errout.str());
|
|
||||||
|
|
||||||
// wanted results - "style" for the public constructor
|
// wanted results - warning for the public constructor
|
||||||
TODO_ASSERT_EQUALS("[test.cpp:5]: (possible style) Member variable not initialized in the constructor 'Foo::foo'\n"
|
TODO_ASSERT_EQUALS("[test.cpp:7]: (style) Member variable not initialized in the constructor 'Foo::foo'\n", errout.str());
|
||||||
"[test.cpp:7]: (style) Member variable not initialized in the constructor 'Foo::foo'\n", errout.str());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ public:
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void check(const char code[], bool style = true, bool all = true)
|
void check(const char code[], bool style = true)
|
||||||
{
|
{
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
Tokenizer tokenizer;
|
Tokenizer tokenizer;
|
||||||
|
@ -47,7 +47,6 @@ private:
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
Settings settings;
|
Settings settings;
|
||||||
settings.inconclusive = all;
|
|
||||||
settings._checkCodingStyle = style;
|
settings._checkCodingStyle = style;
|
||||||
|
|
||||||
// Check for unsigned divisions..
|
// Check for unsigned divisions..
|
||||||
|
@ -59,7 +58,6 @@ private:
|
||||||
{
|
{
|
||||||
TEST_CASE(division1);
|
TEST_CASE(division1);
|
||||||
TEST_CASE(division2);
|
TEST_CASE(division2);
|
||||||
TEST_CASE(division3);
|
|
||||||
TEST_CASE(division4);
|
TEST_CASE(division4);
|
||||||
TEST_CASE(division5);
|
TEST_CASE(division5);
|
||||||
TEST_CASE(division6);
|
TEST_CASE(division6);
|
||||||
|
@ -76,7 +74,8 @@ private:
|
||||||
" unsigned int uvar = 2;\n"
|
" unsigned int uvar = 2;\n"
|
||||||
" return ivar / uvar;\n"
|
" return ivar / uvar;\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:5]: (possible style) Division with signed and unsigned operators\n", errout.str());
|
TODO_ASSERT_EQUALS("[test.cpp:5]: (style) Division with signed and unsigned operators\n", errout.str());
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void division2()
|
void division2()
|
||||||
|
@ -87,20 +86,8 @@ private:
|
||||||
" unsigned int uvar = 2;\n"
|
" unsigned int uvar = 2;\n"
|
||||||
" return uvar / ivar;\n"
|
" return uvar / ivar;\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:5]: (possible style) Division with signed and unsigned operators\n", errout.str());
|
TODO_ASSERT_EQUALS("[test.cpp:5]: (style) Division with signed and unsigned operators\n", errout.str());
|
||||||
}
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
void division3()
|
|
||||||
{
|
|
||||||
check("typedef int s32;\n"
|
|
||||||
"typedef unsigned int u32;\n"
|
|
||||||
"void f()\n"
|
|
||||||
"{\n"
|
|
||||||
" s32 ivar = -2;\n"
|
|
||||||
" u32 uvar = 2;\n"
|
|
||||||
" return uvar / ivar;\n"
|
|
||||||
"}\n");
|
|
||||||
ASSERT_EQUALS("[test.cpp:7]: (possible style) Division with signed and unsigned operators\n", errout.str());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void division4()
|
void division4()
|
||||||
|
@ -155,8 +142,7 @@ private:
|
||||||
check("void foo()\n"
|
check("void foo()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" unsigned int val = 32;\n"
|
" unsigned int val = 32;\n"
|
||||||
" int i = -96 / val; }\n"
|
" int i = -96 / val; }\n");
|
||||||
);
|
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (error) Unsigned division. The result will be wrong.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (error) Unsigned division. The result will be wrong.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,35 +155,26 @@ private:
|
||||||
" unsigned int a;\n"
|
" unsigned int a;\n"
|
||||||
" unsigned int c = a / b;\n"
|
" unsigned int c = a / b;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n", false, true);
|
"}\n", true);
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("void foo(int b)\n"
|
check("void foo(int b)\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" if (b > 0)\n"
|
" if (b < 0)\n"
|
||||||
" {\n"
|
" {\n"
|
||||||
" unsigned int a;\n"
|
" unsigned int a;\n"
|
||||||
" unsigned int c = a / b;\n"
|
" unsigned int c = a / b;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n", true, false);
|
"}\n", true);
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
TODO_ASSERT_EQUALS("unsigned division", errout.str());
|
||||||
check("void foo(int b)\n"
|
|
||||||
"{\n"
|
|
||||||
" if (b > 0)\n"
|
|
||||||
" {\n"
|
|
||||||
" unsigned int a;\n"
|
|
||||||
" unsigned int c = a / b;\n"
|
|
||||||
" }\n"
|
|
||||||
"}\n", true, true);
|
|
||||||
ASSERT_EQUALS("[test.cpp:6]: (possible style) Division with signed and unsigned operators\n", errout.str());
|
|
||||||
|
|
||||||
check("void a(int i) { }\n"
|
check("void a(int i) { }\n"
|
||||||
"int foo( unsigned int sz )\n"
|
"int foo( unsigned int sz )\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" register unsigned int i=1;\n"
|
" register unsigned int i=1;\n"
|
||||||
" return i/sz;\n"
|
" return i/sz;\n"
|
||||||
"}\n", true, true);
|
"}\n", true);
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -209,7 +186,8 @@ private:
|
||||||
" unsigned long uvar = 2;\n"
|
" unsigned long uvar = 2;\n"
|
||||||
" return ivar / uvar;\n"
|
" return ivar / uvar;\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:5]: (possible style) Division with signed and unsigned operators\n", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
TODO_ASSERT_EQUALS("unsigned division", errout.str());
|
||||||
|
|
||||||
check("void f()\n"
|
check("void f()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
@ -217,20 +195,8 @@ private:
|
||||||
" unsigned long long uvar = 2;\n"
|
" unsigned long long uvar = 2;\n"
|
||||||
" return ivar / uvar;\n"
|
" return ivar / uvar;\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:5]: (possible style) Division with signed and unsigned operators\n", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
TODO_ASSERT_EQUALS("unsigned division", errout.str());
|
||||||
check("template<class A, class B> class C\n"
|
|
||||||
"{\n"
|
|
||||||
" A a;\n"
|
|
||||||
" B b;\n"
|
|
||||||
" void foo() { a / b; }\n"
|
|
||||||
"};\n"
|
|
||||||
"C<int, unsigned int> c1;\n"
|
|
||||||
"C<int, unsigned long> c2;\n"
|
|
||||||
"C<int, unsigned long long> c3;\n");
|
|
||||||
ASSERT_EQUALS("[test.cpp:5]: (possible style) Division with signed and unsigned operators\n"
|
|
||||||
"[test.cpp:5]: (possible style) Division with signed and unsigned operators\n"
|
|
||||||
"[test.cpp:5]: (possible style) Division with signed and unsigned operators\n", errout.str());
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -2150,7 +2150,7 @@ private:
|
||||||
" for (it = ab.begin(); it != ab.end(); it++)\n"
|
" for (it = ab.begin(); it != ab.end(); it++)\n"
|
||||||
" ;\n"
|
" ;\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (possible style) Pre-Incrementing variable 'it' is preferred to Post-Incrementing\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (style) Pre-Incrementing variable 'it' is preferred to Post-Incrementing\n", errout.str());
|
||||||
|
|
||||||
checkpostIncrementDecrement("void f1()\n"
|
checkpostIncrementDecrement("void f1()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
@ -2160,8 +2160,8 @@ private:
|
||||||
" for (it = ab.begin(); it != ab.end(); it++)\n"
|
" for (it = ab.begin(); it != ab.end(); it++)\n"
|
||||||
" ;\n"
|
" ;\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (possible style) Pre-Incrementing variable 'it' is preferred to Post-Incrementing\n"
|
ASSERT_EQUALS("[test.cpp:4]: (style) Pre-Incrementing variable 'it' is preferred to Post-Incrementing\n"
|
||||||
"[test.cpp:6]: (possible style) Pre-Incrementing variable 'it' is preferred to Post-Incrementing\n", errout.str());
|
"[test.cpp:6]: (style) Pre-Incrementing variable 'it' is preferred to Post-Incrementing\n", errout.str());
|
||||||
|
|
||||||
checkpostIncrementDecrement("void f2()\n"
|
checkpostIncrementDecrement("void f2()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
@ -2169,7 +2169,7 @@ private:
|
||||||
" for (it = ab.end(); it != ab.begin(); it--)\n"
|
" for (it = ab.end(); it != ab.begin(); it--)\n"
|
||||||
" ;\n"
|
" ;\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (possible style) Pre-Decrementing variable 'it' is preferred to Post-Decrementing\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (style) Pre-Decrementing variable 'it' is preferred to Post-Decrementing\n", errout.str());
|
||||||
|
|
||||||
checkpostIncrementDecrement("void f2()\n"
|
checkpostIncrementDecrement("void f2()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
@ -2179,8 +2179,8 @@ private:
|
||||||
" for (it = ab.end(); it != ab.begin(); it--)\n"
|
" for (it = ab.end(); it != ab.begin(); it--)\n"
|
||||||
" ;\n"
|
" ;\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (possible style) Pre-Decrementing variable 'it' is preferred to Post-Decrementing\n"
|
ASSERT_EQUALS("[test.cpp:4]: (style) Pre-Decrementing variable 'it' is preferred to Post-Decrementing\n"
|
||||||
"[test.cpp:6]: (possible style) Pre-Decrementing variable 'it' is preferred to Post-Decrementing\n", errout.str());
|
"[test.cpp:6]: (style) Pre-Decrementing variable 'it' is preferred to Post-Decrementing\n", errout.str());
|
||||||
|
|
||||||
checkpostIncrementDecrement("void f1()\n"
|
checkpostIncrementDecrement("void f1()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
@ -2188,7 +2188,7 @@ private:
|
||||||
" for (it = ab.begin(); it != ab.end(); it++)\n"
|
" for (it = ab.begin(); it != ab.end(); it++)\n"
|
||||||
" ;\n"
|
" ;\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (possible style) Pre-Incrementing variable 'it' is preferred to Post-Incrementing\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (style) Pre-Incrementing variable 'it' is preferred to Post-Incrementing\n", errout.str());
|
||||||
|
|
||||||
checkpostIncrementDecrement("void f1()\n"
|
checkpostIncrementDecrement("void f1()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
@ -2196,7 +2196,7 @@ private:
|
||||||
" for (it = ab.begin(); it != ab.end(); it++)\n"
|
" for (it = ab.begin(); it != ab.end(); it++)\n"
|
||||||
" ;\n"
|
" ;\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (possible style) Pre-Incrementing variable 'it' is preferred to Post-Incrementing\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (style) Pre-Incrementing variable 'it' is preferred to Post-Incrementing\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void postIncrementDecrementClass()
|
void postIncrementDecrementClass()
|
||||||
|
@ -2208,7 +2208,7 @@ private:
|
||||||
" for (tClass = TestClass.begin(); tClass != TestClass.end(); tClass++)\n"
|
" for (tClass = TestClass.begin(); tClass != TestClass.end(); tClass++)\n"
|
||||||
" ;\n"
|
" ;\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:5]: (possible style) Pre-Incrementing variable 'tClass' is preferred to Post-Incrementing\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:5]: (style) Pre-Incrementing variable 'tClass' is preferred to Post-Incrementing\n", errout.str());
|
||||||
|
|
||||||
checkpostIncrementDecrement("class TestClass;\n"
|
checkpostIncrementDecrement("class TestClass;\n"
|
||||||
"void f1()\n"
|
"void f1()\n"
|
||||||
|
@ -2217,7 +2217,7 @@ private:
|
||||||
" for (tClass = TestClass.end(); tClass != TestClass.begin(); tClass--)\n"
|
" for (tClass = TestClass.end(); tClass != TestClass.begin(); tClass--)\n"
|
||||||
" ;\n"
|
" ;\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:5]: (possible style) Pre-Decrementing variable 'tClass' is preferred to Post-Decrementing\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:5]: (style) Pre-Decrementing variable 'tClass' is preferred to Post-Decrementing\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void dangerousStrolUsage()
|
void dangerousStrolUsage()
|
||||||
|
|
|
@ -819,28 +819,28 @@ private:
|
||||||
" std::list<int> x;\n"
|
" std::list<int> x;\n"
|
||||||
" if (x.size() == 0) {}\n"
|
" if (x.size() == 0) {}\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (possible style) Use x.empty() instead of x.size() to guarantee fast code.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (style) Use x.empty() instead of x.size() to guarantee fast code.\n", errout.str());
|
||||||
|
|
||||||
check("void f()\n"
|
check("void f()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" std::list<int> x;\n"
|
" std::list<int> x;\n"
|
||||||
" if (x.size() != 0) {}\n"
|
" if (x.size() != 0) {}\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (possible style) Use x.empty() instead of x.size() to guarantee fast code.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (style) Use x.empty() instead of x.size() to guarantee fast code.\n", errout.str());
|
||||||
|
|
||||||
check("void f()\n"
|
check("void f()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" std::list<int> x;\n"
|
" std::list<int> x;\n"
|
||||||
" if (x.size() > 0) {}\n"
|
" if (x.size() > 0) {}\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (possible style) Use x.empty() instead of x.size() to guarantee fast code.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (style) Use x.empty() instead of x.size() to guarantee fast code.\n", errout.str());
|
||||||
|
|
||||||
check("void f()\n"
|
check("void f()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" std::list<int> x;\n"
|
" std::list<int> x;\n"
|
||||||
" if (x.size()) {}\n"
|
" if (x.size()) {}\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (possible style) Use x.empty() instead of x.size() to guarantee fast code.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (style) Use x.empty() instead of x.size() to guarantee fast code.\n", errout.str());
|
||||||
|
|
||||||
check("void f()\n"
|
check("void f()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
|
Loading…
Reference in New Issue