Skip to content

Commit 6b9ac6f

Browse files
authored
Warn when incrementing uninitialized value (#4042)
* Warn when incrementing uninitialized value * Format
1 parent 5d55622 commit 6b9ac6f

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

lib/checkuninitvar.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1579,7 +1579,7 @@ static ExprUsage getExprUsage(const Token* tok, int indirect, const Settings* se
15791579
if (tok->astParent()->isCast())
15801580
return ExprUsage::NotUsed;
15811581
}
1582-
if (indirect == 0 && Token::Match(tok->astParent(), "%cop%|%assign%") && tok->astParent()->str() != "=")
1582+
if (indirect == 0 && Token::Match(tok->astParent(), "%cop%|%assign%|++|--") && tok->astParent()->str() != "=")
15831583
return ExprUsage::Used;
15841584
return getFunctionUsage(tok, indirect, settings);
15851585
}

test/testuninitvar.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5285,6 +5285,12 @@ class TestUninitVar : public TestFixture {
52855285
" g(p->x);\n"
52865286
"}\n");
52875287
ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:8]: (error) Uninitialized variable: p->x\n", errout.str());
5288+
5289+
valueFlowUninit("void f() {\n"
5290+
" int a;\n"
5291+
" a++;\n"
5292+
"}\n");
5293+
ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: a\n", errout.str());
52885294
}
52895295

52905296
void valueFlowUninitBreak() { // Do not show duplicate warnings about the same uninitialized value

0 commit comments

Comments
 (0)