Robert Reif: Fixed #1139 (false negative: CheckOther::postIncrement() only finds at most one problem)

This commit is contained in:
Daniel Marjamäki 2009-12-23 13:38:54 +01:00
parent fe74c65c89
commit 5a89cc3259
2 changed files with 22 additions and 2 deletions

View File

@ -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;
}
}
}

View File

@ -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<int>::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<int>::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<int>::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()