diff --git a/src/checkother.cpp b/src/checkother.cpp index 242729786..9613a35dc 100644 --- a/src/checkother.cpp +++ b/src/checkother.cpp @@ -1160,7 +1160,7 @@ void CheckOther::postIncrement() if (decltok && Token::Match(decltok->previous(), "iterator|const_iterator")) postIncrementError(tok2, tok2->strAt(1), (std::string("++") == tok2->strAt(2))); // 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))); 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) { - std::string type = ( isIncrement ? "Incrementing" : "Decrementing" ); - reportError(tok, Severity::possibleStyle, "postIncrementDecrement", ("Pre-" + type + " variable '" + var_name + "' is preferred to Post-" + type) ); + std::string type = (isIncrement ? "Incrementing" : "Decrementing"); + reportError(tok, Severity::possibleStyle, "postIncrementDecrement", ("Pre-" + type + " variable '" + var_name + "' is preferred to Post-" + type)); } diff --git a/src/checkstl.cpp b/src/checkstl.cpp index a8a9bb572..2c9eb40b5 100644 --- a/src/checkstl.cpp +++ b/src/checkstl.cpp @@ -370,9 +370,9 @@ void CheckStl::stlBoundries() { // Declaring iterator.. 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() != ">") tok = tok->next(); if (!tok) diff --git a/test/testother.cpp b/test/testother.cpp index 73c454bd0..65c60b837 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -639,43 +639,43 @@ private: void postIncrementDecrementStl() { - checkpostIncrementDecrement("void f1()\n" - "{\n" - " std::list::iterator it;\n" - " for (it = ab.begin(); it != ab.end(); it++)\n" - " ;\n" - "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (possible style) Pre-Incrementing variable 'it' is preferred to Post-Incrementing\n", errout.str()); + checkpostIncrementDecrement("void f1()\n" + "{\n" + " std::list::iterator it;\n" + " for (it = ab.begin(); it != ab.end(); it++)\n" + " ;\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:4]: (possible style) Pre-Incrementing variable 'it' is preferred to Post-Incrementing\n", errout.str()); - checkpostIncrementDecrement("void f2()\n" - "{\n" - " std::list::iterator it;\n" - " for (it = ab.end(); it != ab.begin(); it--)\n" - " ;\n" - "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (possible style) Pre-Decrementing variable 'it' is preferred to Post-Decrementing\n", errout.str()); + checkpostIncrementDecrement("void f2()\n" + "{\n" + " std::list::iterator it;\n" + " for (it = ab.end(); it != ab.begin(); it--)\n" + " ;\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:4]: (possible style) Pre-Decrementing variable 'it' is preferred to Post-Decrementing\n", errout.str()); } - void postIncrementDecrementClass() - { - checkpostIncrementDecrement("class TestClass;\n" - "void f1()\n" - "{\n" - " TestClass tClass;\n" - " for (tClass = TestClass.begin(); tClass != TestClass.end(); tClass++)\n" - " ;\n" - "}\n"); - ASSERT_EQUALS("[test.cpp:5]: (possible style) Pre-Incrementing variable 'tClass' is preferred to Post-Incrementing\n", errout.str()); + void postIncrementDecrementClass() + { + checkpostIncrementDecrement("class TestClass;\n" + "void f1()\n" + "{\n" + " TestClass tClass;\n" + " for (tClass = TestClass.begin(); tClass != TestClass.end(); tClass++)\n" + " ;\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:5]: (possible style) Pre-Incrementing variable 'tClass' is preferred to Post-Incrementing\n", errout.str()); - checkpostIncrementDecrement("class TestClass;\n" - "void f1()\n" - "{\n" - " TestClass tClass;\n" - " for (tClass = TestClass.end(); tClass != TestClass.begin(); tClass--)\n" - " ;\n" - "}\n"); - ASSERT_EQUALS("[test.cpp:5]: (possible style) Pre-Decrementing variable 'tClass' is preferred to Post-Decrementing\n", errout.str()); - } + checkpostIncrementDecrement("class TestClass;\n" + "void f1()\n" + "{\n" + " TestClass tClass;\n" + " for (tClass = TestClass.end(); tClass != TestClass.begin(); tClass--)\n" + " ;\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:5]: (possible style) Pre-Decrementing variable 'tClass' is preferred to Post-Decrementing\n", errout.str()); + } }; diff --git a/test/teststl.cpp b/test/teststl.cpp index 0d068e536..8429eeec6 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -377,19 +377,20 @@ private: { const int STL_CONTAINER_LIST = 10; const std::string stlCont[STL_CONTAINER_LIST] = - {"vector", "deque", "list", "set", "multiset", "map", - "multimap", "hash_map", "hash_multimap", "hash_set"}; + {"vector", "deque", "list", "set", "multiset", "map", + "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" - "{\n" - " std::" + stlCont[i] + "::iterator it;\n" - " for (it = ab.begin(); it < ab.end(); ++it)\n" - " ;\n" - "}\n" ); + const std::string checkStr("void f()\n" + "{\n" + " std::" + stlCont[i] + "::iterator it;\n" + " for (it = ab.begin(); it < ab.end(); ++it)\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()); }