From 3e549800875c9c32a37bf519479f34ace81fd250 Mon Sep 17 00:00:00 2001 From: olabetskyi <153490942+olabetskyi@users.noreply.github.com> Date: Sat, 8 Jun 2024 19:17:12 +0300 Subject: [PATCH] Fix #4478: FP: Uninitialized variable (#6493) --- lib/astutils.cpp | 2 ++ test/testuninitvar.cpp | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/astutils.cpp b/lib/astutils.cpp index 3f45dea5cfc..0493b1ab668 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -3415,6 +3415,8 @@ ExprUsage getExprUsage(const Token* tok, int indirect, const Settings& settings) if (isUsedAsBool(tok, settings)) return ExprUsage::NotUsed; } + if (tok->isUnaryOp("&") && !parent) + return ExprUsage::NotUsed; if (indirect == 0) { if (Token::Match(parent, "%cop%|%assign%|++|--") && parent->str() != "=" && !parent->isUnaryOp("&") && diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index 82317f9b26b..440118caafd 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -4304,7 +4304,7 @@ class TestUninitVar : public TestFixture { " long a;\n" " &a;\n" "}"); - TODO_ASSERT_EQUALS("", "[test.cpp:3]: (error) Uninitialized variable: &a\n", errout_str()); + ASSERT_EQUALS("", errout_str()); valueFlowUninit("void f() {\n" // #4717 - ({}) " int a = ({ long b = (long)(123); 2 + b; });\n"