diff --git a/lib/astutils.cpp b/lib/astutils.cpp index 371b6fa29bc..db5058b073c 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -3149,7 +3149,7 @@ ExprUsage getExprUsage(const Token* tok, int indirect, const Settings* settings, return ExprUsage::Used; if (Token::simpleMatch(parent, "=") && astIsRHS(tok)) { const Token* const lhs = parent->astOperand1(); - if (lhs && lhs->variable() && lhs->variable()->isReference() && lhs->variable()->nameToken()) + if (lhs && lhs->variable() && lhs->variable()->isReference() && lhs == lhs->variable()->nameToken()) return ExprUsage::NotUsed; return ExprUsage::Used; } diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index 994b2adf4d6..4b634a1f96a 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -6191,6 +6191,12 @@ class TestUninitVar : public TestFixture { " return i >> *p;\n" "}\n"); ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: *p\n", errout.str()); + + valueFlowUninit("void f(int& x) {\n" + " int i;\n" + " x = i;\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: i\n", errout.str()); } void valueFlowUninitBreak() { // Do not show duplicate warnings about the same uninitialized value