diff --git a/lib/astutils.cpp b/lib/astutils.cpp index f417ad704ff..2d662062914 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -3249,9 +3249,11 @@ static ExprUsage getFunctionUsage(const Token* tok, int indirect, const Settings ExprUsage getExprUsage(const Token* tok, int indirect, const Settings* settings, bool cpp) { - const Token* const parent = tok->astParent(); + const Token* parent = tok->astParent(); if (indirect > 0 && parent) { - if (Token::Match(parent, "%assign%") && astIsRHS(tok)) + while (Token::simpleMatch(parent, "[") && parent->astParent()) + parent = parent->astParent(); + if (Token::Match(parent, "%assign%") && (astIsRHS(tok) || astIsLHS(parent->astOperand1()))) return ExprUsage::NotUsed; if (parent->isConstOp()) return ExprUsage::NotUsed; diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index 6e4abe8d876..1045f709abc 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -6289,6 +6289,14 @@ class TestUninitVar : public TestFixture { " foo(q);\n" "}\n"); ASSERT_EQUALS("[test.cpp:9]: (error) Uninitialized variable: q\n", errout.str()); + + valueFlowUninit("int g();\n" // #12082 + "void f() {\n" + " int a[1], b[1];\n" + " while (a[0] = g()) {}\n" + " if ((b[0] = g()) == 0) {}\n" + "}"); + ASSERT_EQUALS("", errout.str()); } void valueFlowUninitBreak() { // Do not show duplicate warnings about the same uninitialized value