astyle FTW (should have read about that sooner)
This commit is contained in:
parent
52e2e775b2
commit
9fa8c0ee9c
|
@ -1160,7 +1160,7 @@ void CheckOther::postIncrement()
|
||||||
if (decltok && Token::Match(decltok->previous(), "iterator|const_iterator"))
|
if (decltok && Token::Match(decltok->previous(), "iterator|const_iterator"))
|
||||||
postIncrementError(tok2, tok2->strAt(1), (std::string("++") == tok2->strAt(2)));
|
postIncrementError(tok2, tok2->strAt(1), (std::string("++") == tok2->strAt(2)));
|
||||||
// Is the variable a class?
|
// Is the variable a class?
|
||||||
else if (Token::findmatch( _tokenizer->tokens(), classDef.c_str() ))
|
else if (Token::findmatch(_tokenizer->tokens(), classDef.c_str()))
|
||||||
postIncrementError(tok2, tok2->strAt(1), (std::string("++") == tok2->strAt(2)));
|
postIncrementError(tok2, tok2->strAt(1), (std::string("++") == tok2->strAt(2)));
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
@ -1264,6 +1264,6 @@ void CheckOther::zerodivError(const Token *tok)
|
||||||
|
|
||||||
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::possibleStyle, "postIncrementDecrement", ("Pre-" + type + " variable '" + var_name + "' is preferred to Post-" + type));
|
||||||
}
|
}
|
||||||
|
|
|
@ -370,9 +370,9 @@ void CheckStl::stlBoundries()
|
||||||
{
|
{
|
||||||
// Declaring iterator..
|
// Declaring iterator..
|
||||||
const std::string checkStr = (std::string(STL_CONTAINER_LIST) + " <");
|
const std::string checkStr = (std::string(STL_CONTAINER_LIST) + " <");
|
||||||
if (Token::Match( tok, checkStr.c_str() ))
|
if (Token::Match(tok, checkStr.c_str()))
|
||||||
{
|
{
|
||||||
const std::string container_name( tok->strAt(0) );
|
const std::string container_name(tok->strAt(0));
|
||||||
while (tok && tok->str() != ">")
|
while (tok && tok->str() != ">")
|
||||||
tok = tok->next();
|
tok = tok->next();
|
||||||
if (!tok)
|
if (!tok)
|
||||||
|
|
|
@ -639,43 +639,43 @@ private:
|
||||||
|
|
||||||
void postIncrementDecrementStl()
|
void postIncrementDecrementStl()
|
||||||
{
|
{
|
||||||
checkpostIncrementDecrement("void f1()\n"
|
checkpostIncrementDecrement("void f1()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" std::list<int>::iterator it;\n"
|
" std::list<int>::iterator it;\n"
|
||||||
" 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]: (possible style) Pre-Incrementing variable 'it' is preferred to Post-Incrementing\n", errout.str());
|
||||||
|
|
||||||
checkpostIncrementDecrement("void f2()\n"
|
checkpostIncrementDecrement("void f2()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" std::list<int>::iterator it;\n"
|
" std::list<int>::iterator it;\n"
|
||||||
" 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]: (possible style) Pre-Decrementing variable 'it' is preferred to Post-Decrementing\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void postIncrementDecrementClass()
|
void postIncrementDecrementClass()
|
||||||
{
|
{
|
||||||
checkpostIncrementDecrement("class TestClass;\n"
|
checkpostIncrementDecrement("class TestClass;\n"
|
||||||
"void f1()\n"
|
"void f1()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" TestClass tClass;\n"
|
" TestClass tClass;\n"
|
||||||
" 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]: (possible 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"
|
||||||
"{\n"
|
"{\n"
|
||||||
" TestClass tClass;\n"
|
" TestClass tClass;\n"
|
||||||
" 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]: (possible style) Pre-Decrementing variable 'tClass' is preferred to Post-Decrementing\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -377,19 +377,20 @@ private:
|
||||||
{
|
{
|
||||||
const int STL_CONTAINER_LIST = 10;
|
const int STL_CONTAINER_LIST = 10;
|
||||||
const std::string stlCont[STL_CONTAINER_LIST] =
|
const std::string stlCont[STL_CONTAINER_LIST] =
|
||||||
{"vector", "deque", "list", "set", "multiset", "map",
|
{"vector", "deque", "list", "set", "multiset", "map",
|
||||||
"multimap", "hash_map", "hash_multimap", "hash_set"};
|
"multimap", "hash_map", "hash_multimap", "hash_set"
|
||||||
|
};
|
||||||
|
|
||||||
for(int i = 0; i < STL_CONTAINER_LIST; ++i)
|
for (int i = 0; i < STL_CONTAINER_LIST; ++i)
|
||||||
{
|
{
|
||||||
const std::string checkStr( "void f()\n"
|
const std::string checkStr("void f()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" std::" + stlCont[i] + "<int>::iterator it;\n"
|
" std::" + stlCont[i] + "<int>::iterator it;\n"
|
||||||
" for (it = ab.begin(); it < ab.end(); ++it)\n"
|
" for (it = ab.begin(); it < ab.end(); ++it)\n"
|
||||||
" ;\n"
|
" ;\n"
|
||||||
"}\n" );
|
"}\n");
|
||||||
|
|
||||||
check( checkStr.c_str() );
|
check(checkStr.c_str());
|
||||||
|
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (error) " + stlCont[i] + " range check should use != and not < since the order of the pointers isn't guaranteed\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (error) " + stlCont[i] + " range check should use != and not < since the order of the pointers isn't guaranteed\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue