diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 9551b2302..cb4537668 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -4896,7 +4896,8 @@ bool Tokenizer::simplifyKnownVariables() Token::Match(tok2, "%var% [ ] = %str% ;") || Token::Match(tok2, "%var% = %bool% ;") || Token::Match(tok2, "%var% = %var% ;") || - Token::Match(tok2, "%var% = & %var% ;"))) + Token::Match(tok2, "%var% = & %var% ;") || + Token::Match(tok2, "%var% = & %var% [ 0 ] ;"))) { const unsigned int varid = tok2->varId(); if (varid == 0) @@ -5008,7 +5009,7 @@ bool Tokenizer::simplifyKnownVariables() } // Variable is used in calculation.. - if (Token::Match(tok3, "[=+-*/[] %varid% [?+-*/;]]", varid) || + if (Token::Match(tok3, "[=+-*/[] %varid% [=?+-*/;]]", varid) || Token::Match(tok3, "[(=+-*/[] %varid% <<|>>", varid) || Token::Match(tok3, "<< %varid% [+-*/;])]", varid) || Token::Match(tok3, ">> %varid% [+-*/])]", varid)) diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index d0882eacc..a2f3ea89e 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -192,6 +192,7 @@ private: TEST_CASE(pointeralias1); TEST_CASE(pointeralias2); TEST_CASE(pointeralias3); + TEST_CASE(pointeralias4); TEST_CASE(reduceConstness); @@ -4126,6 +4127,23 @@ private: ASSERT_EQUALS(expected, tok(code)); } + void pointeralias4() + { + const char code[] = "void f()\n" + "{\n" + " int a[10];\n" + " int *p = &a[0];\n" + " *p = 0;\n" + "}\n"; + const char expected[] = "void f ( ) " + "{" + " int a [ 10 ] ;" + " int * p ; p = & a [ 0 ] ;" + " * a = 0 ; " + "}"; + ASSERT_EQUALS(expected, tok(code)); + } + void reduceConstness() {