Fix ticket #317 (pre-increment causes style false positive)

This commit is contained in:
Daniel Marjamäki 2009-05-25 08:26:11 +02:00
parent 977e31786d
commit 7fdd497c44
2 changed files with 17 additions and 1 deletions

View File

@ -2255,7 +2255,7 @@ bool Tokenizer::simplifyKnownVariables()
if (Token::Match(tok3->next(), "%varid% ++|--", varid))
{
const std::string op(tok3->strAt(2));
if (Token::Match(tok3, "; %any% %any% ;"))
if (Token::Match(tok3, "[{};] %any% %any% ;"))
{
tok3->deleteNext();
tok3->deleteNext();

View File

@ -67,6 +67,8 @@ private:
TEST_CASE(paranthesesVar); // Remove redundant parantheses around variable .. "( %var% )"
TEST_CASE(declareVar);
TEST_CASE(removePostIncrement);
TEST_CASE(elseif1);
TEST_CASE(sizeof1);
@ -378,6 +380,20 @@ private:
ASSERT_EQUALS(code, tok(code));
}
void removePostIncrement()
{
const char code[] = "void f()\n"
"{\n"
" unsigned int c = 0;\n"
" c++;\n"
" if (c>0) { c++; }\n"
" c++;\n"
"}\n";
ASSERT_EQUALS(std::string("void f ( ) { int c ; c = 3 ; ; { ; } ; } "), tok(code));
}
std::string elseif(const char code[])
{
std::istringstream istr(code);