diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 5baa921cf..b5229d3ce 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -1612,8 +1612,6 @@ void CheckOther::postIncrement() // Is the variable a class? else if (Token::findmatch(_tokenizer->tokens(), classDef.c_str())) postIncrementError(tok2, tok2->strAt(1), (std::string("++") == tok2->strAt(2))); - - break; } } } diff --git a/test/testother.cpp b/test/testother.cpp index 539c4d0fc..e4444ddcf 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -1409,6 +1409,17 @@ private: "}\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" + " 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" + "[test.cpp:6]: (possible style) Pre-Incrementing variable 'it' is preferred to Post-Incrementing\n", errout.str()); + checkpostIncrementDecrement("void f2()\n" "{\n" " std::list::iterator it;\n" @@ -1416,6 +1427,17 @@ private: " ;\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" + " 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" + "[test.cpp:6]: (possible style) Pre-Decrementing variable 'it' is preferred to Post-Decrementing\n", errout.str()); } void postIncrementDecrementClass()