Fix issue 9678: False positive: generic valueflow forward analysis (#2611)

This commit is contained in:
Paul Fultz II 2020-04-19 01:28:07 -05:00 committed by GitHub
parent 54978847c5
commit e2efb338b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 1 deletions

View File

@ -3714,7 +3714,11 @@ static void valueFlowForwardAssign(Token * const tok,
ErrorLogger * const errorLogger,
const Settings * const settings)
{
const Token * const endOfVarScope = var->scope()->bodyEnd;
const Token * endOfVarScope = nullptr;
if (var->isLocal())
endOfVarScope = var->scope()->bodyEnd;
if (!endOfVarScope)
endOfVarScope = tok->scope()->bodyEnd;
if (std::any_of(values.begin(), values.end(), std::mem_fn(&ValueFlow::Value::isLifetimeValue))) {
valueFlowForwardLifetime(tok, tokenlist, errorLogger, settings);
values.remove_if(std::mem_fn(&ValueFlow::Value::isLifetimeValue));

View File

@ -2034,6 +2034,19 @@ private:
"}\n";
ASSERT_EQUALS(false, testValueOfX(code, 6U, 3));
TODO_ASSERT_EQUALS(true, false, testValueOfX(code, 6U, 2));
code = "struct Fred {\n"
" static void Create(std::unique_ptr<Wilma> wilma);\n"
" Fred(std::unique_ptr<Wilma> wilma);\n"
" std::unique_ptr<Wilma> mWilma;\n"
"};\n"
"void Fred::Create(std::unique_ptr<Wilma> wilma) {\n"
" auto fred = std::make_shared<Fred>(std::move(wilma));\n"
" fred->mWilma.reset();\n"
"}\n"
"Fred::Fred(std::unique_ptr<Wilma> wilma)\n"
" : mWilma(std::move(wilma)) {}\n";
ASSERT_EQUALS(0, tokenValues(code, "mWilma (").size());
}
void valueFlowAfterCondition() {