diff --git a/lib/checkcondition.cpp b/lib/checkcondition.cpp index 18fa4e0ee..27999245a 100644 --- a/lib/checkcondition.cpp +++ b/lib/checkcondition.cpp @@ -491,7 +491,7 @@ void CheckCondition::multiCondition2() nonlocal |= (var && (var->isPointer() || var->isReference())); } else if (!nonlocal && cond->isName()) { // varid is 0. this is possibly a nonlocal variable.. - nonlocal = Token::Match(cond->astParent(), "%cop%|("); + nonlocal = Token::Match(cond->astParent(), "%cop%|(|["); } else { tokens.push(cond->astOperand1()); tokens.push(cond->astOperand2()); diff --git a/test/testcondition.cpp b/test/testcondition.cpp index 7ad2ba401..8cce0d1e6 100644 --- a/test/testcondition.cpp +++ b/test/testcondition.cpp @@ -1532,6 +1532,15 @@ private: "}"); ASSERT_EQUALS("", errout.str()); + // undeclared array + check("void f(int x) {\n" + " if (a[x] > 0) {\n" + " a[x] -= dt;\n" + " if (a[x] < 0) {}\n" + " }\n" + "}"); + ASSERT_EQUALS("", errout.str()); + // #6313 - false positive: opposite conditions in nested if blocks when condition changed check("void Foo::Bar() {\n" " if(var){\n"