Skip to content

Commit 3e54980

Browse files
authored
Fix #4478: FP: Uninitialized variable (#6493)
1 parent f1ddd1a commit 3e54980

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

lib/astutils.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -3415,6 +3415,8 @@ ExprUsage getExprUsage(const Token* tok, int indirect, const Settings& settings)
34153415
if (isUsedAsBool(tok, settings))
34163416
return ExprUsage::NotUsed;
34173417
}
3418+
if (tok->isUnaryOp("&") && !parent)
3419+
return ExprUsage::NotUsed;
34183420
if (indirect == 0) {
34193421
if (Token::Match(parent, "%cop%|%assign%|++|--") && parent->str() != "=" &&
34203422
!parent->isUnaryOp("&") &&

test/testuninitvar.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -4304,7 +4304,7 @@ class TestUninitVar : public TestFixture {
43044304
" long a;\n"
43054305
" &a;\n"
43064306
"}");
4307-
TODO_ASSERT_EQUALS("", "[test.cpp:3]: (error) Uninitialized variable: &a\n", errout_str());
4307+
ASSERT_EQUALS("", errout_str());
43084308

43094309
valueFlowUninit("void f() {\n" // #4717 - ({})
43104310
" int a = ({ long b = (long)(123); 2 + b; });\n"

0 commit comments

Comments
 (0)