diff --git a/lib/astutils.cpp b/lib/astutils.cpp index ea54232b551..2a231dccfd5 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -2778,7 +2778,7 @@ bool isVariableChanged(const Token *tok, int indirect, const Settings &settings, if (ftok->str() == "(" && Token::simpleMatch(ftok->astOperand1(), "[")) // operator() on array element, bail out return true; const Token * ptok = tok2; - while (Token::Match(ptok->astParent(), ".|::|[")) + while (Token::Match(ptok->astParent(), ".|::")) ptok = ptok->astParent(); int pindirect = indirect; if (indirect == 0 && astIsLHS(tok2) && Token::Match(ptok, ". %var%") && astIsPointer(ptok->next())) diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index abeb603b660..45c7f884715 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -5112,6 +5112,27 @@ class TestValueFlow : public TestFixture { ++it; ASSERT_EQUALS(0, it->intvalue); ASSERT(it->isPossible()); + + code = "void g(int*);\n" + "void f(int* a) {\n" + " for (int i = 0; i < 5; ++i) {\n" + " g(&a[i]);\n" + " }\n" + "}\n"; + values = tokenValues(code, "i ]"); + ASSERT_EQUALS(4, values.size()); + it = values.begin(); + ASSERT_EQUALS(0, it->intvalue); + ASSERT(it->isPossible()); + ++it; + ASSERT_EQUALS(-1, it->intvalue); + ASSERT(it->isImpossible()); + ++it; + ASSERT_EQUALS(4, it->intvalue); + ASSERT(it->isPossible()); + ++it; + ASSERT_EQUALS(5, it->intvalue); + ASSERT(it->isImpossible()); } void valueFlowSubFunction() {