diff --git a/src/tokenize.cpp b/src/tokenize.cpp index 5f9846bdb..45f47bb1d 100644 --- a/src/tokenize.cpp +++ b/src/tokenize.cpp @@ -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(); diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 622eee2b0..1ce68068d 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -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);