diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index f521ed475..ded536ef8 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -3676,7 +3676,8 @@ bool Tokenizer::simplifyKnownVariables() ret = true; } - if (Token::Match(tok3->next(), "++|-- %varid% !!.", varid)) + if (Token::Match(tok3->next(), "++|-- %varid%", varid) && + !Token::Match(tok3->tokAt(3), "[.[]")) { incdec(value, tok3->strAt(1)); tok2->tokAt(2)->str(value); diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 6eaf91c9b..a59920497 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -515,14 +515,25 @@ private: void removePreIncrement() { - const char code[] = "void f()\n" - "{\n" - " unsigned int c = 0;\n" - " ++c;\n" - " if (c>0) { ++c; }\n" - " ++c;\n" - "}\n"; - ASSERT_EQUALS("void f ( ) { int c ; c = 3 ; ; { ; } ; }", tok(code)); + { + const char code[] = "void f()\n" + "{\n" + " unsigned int c = 0;\n" + " ++c;\n" + " if (c>0) { ++c; }\n" + " ++c;\n" + "}\n"; + ASSERT_EQUALS("void f ( ) { int c ; c = 3 ; ; { ; } ; }", tok(code)); + } + + { + const char code[] = "void f()\n" + "{\n" + " char a[] = \"p\";\n" + " ++a[0];\n" + "}\n"; + ASSERT_EQUALS("void f ( ) { char * a ; a = \"p\" ; ++ a [ 0 ] ; }", tok(code)); + } }