From c533e803e9076aafed57d51f5fa7b8d4ed16a689 Mon Sep 17 00:00:00 2001 From: chrchr-github Date: Fri, 11 Aug 2023 22:42:56 +0200 Subject: [PATCH] Fix regression --- lib/astutils.cpp | 2 +- test/testuninitvar.cpp | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) 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