Fix regression: unreadVariable for trivial initialization (#3698)
This commit is contained in:
parent
1b89c998f5
commit
7aa0ec3e95
|
@ -1183,6 +1183,9 @@ void CheckUnusedVar::checkFunctionVariableUsage()
|
|||
if (!isAssignment && !isInitialization && !isIncrementOrDecrement)
|
||||
continue;
|
||||
|
||||
if (isInitialization && Token::Match(tok, "%var% { }")) // don't warn for trivial initialization
|
||||
continue;
|
||||
|
||||
if (isIncrementOrDecrement && tok->astParent() && precedes(tok, tok->astOperand1()))
|
||||
continue;
|
||||
|
||||
|
|
|
@ -3040,6 +3040,19 @@ private:
|
|||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
functionVariableUsage("void f(bool b, bool c, double& r) {\n"
|
||||
" double d{};\n"
|
||||
" if (b) {\n"
|
||||
" d = g();\n"
|
||||
" r += d;\n"
|
||||
" }\n"
|
||||
" if (c) {\n"
|
||||
" d = h();\n"
|
||||
" r += d;\n"
|
||||
" }\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
functionVariableUsage("int func() {\n"
|
||||
" std::mutex m;\n"
|
||||
" std::unique_lock<std::mutex> l{ m };\n"
|
||||
|
|
Loading…
Reference in New Issue