diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index b99f04522..ff6546704 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -3405,7 +3405,7 @@ bool Tokenizer::simplifyKnownVariables() Token::Match(tok2, "%var% = %bool% ;") || Token::Match(tok2, "%var% = %var% ;"))) { - unsigned int varid = tok2->varId(); + const unsigned int varid = tok2->varId(); if (varid == 0) continue; @@ -3522,7 +3522,7 @@ bool Tokenizer::simplifyKnownVariables() ret = true; } - if (Token::Match(tok3->next(), "++|-- %varid%", varid)) + if (Token::Match(tok3->next(), "++|-- %varid% !!.", varid)) { incdec(value, tok3->strAt(1)); tok2->tokAt(2)->str(value); diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 641c372c7..4f8e9a94a 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -2197,6 +2197,22 @@ private: ASSERT_EQUALS(expected, tok(code)); } + + { + const char code[] = "void foo(Result* ptr)\n" + "{\n" + " Result* obj = ptr;\n" + " ++obj->total;\n" + "}\n"; + + const char expected[] = "void foo ( Result * ptr ) " + "{ " + "Result * obj ; obj = ptr ; " + "++ obj . total ; " + "}"; + + ASSERT_EQUALS(expected, tok(code)); + } }