Warn when incrementing uninitialized value (#4042)
* Warn when incrementing uninitialized value * Format
This commit is contained in:
parent
5d5562266d
commit
6b9ac6f7a8
|
@ -1579,7 +1579,7 @@ static ExprUsage getExprUsage(const Token* tok, int indirect, const Settings* se
|
|||
if (tok->astParent()->isCast())
|
||||
return ExprUsage::NotUsed;
|
||||
}
|
||||
if (indirect == 0 && Token::Match(tok->astParent(), "%cop%|%assign%") && tok->astParent()->str() != "=")
|
||||
if (indirect == 0 && Token::Match(tok->astParent(), "%cop%|%assign%|++|--") && tok->astParent()->str() != "=")
|
||||
return ExprUsage::Used;
|
||||
return getFunctionUsage(tok, indirect, settings);
|
||||
}
|
||||
|
|
|
@ -5285,6 +5285,12 @@ private:
|
|||
" g(p->x);\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:8]: (error) Uninitialized variable: p->x\n", errout.str());
|
||||
|
||||
valueFlowUninit("void f() {\n"
|
||||
" int a;\n"
|
||||
" a++;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: a\n", errout.str());
|
||||
}
|
||||
|
||||
void valueFlowUninitBreak() { // Do not show duplicate warnings about the same uninitialized value
|
||||
|
|
Loading…
Reference in New Issue