Fix issue 9678: False positive: generic valueflow forward analysis (#2611)
This commit is contained in:
parent
54978847c5
commit
e2efb338b6
|
@ -3714,7 +3714,11 @@ static void valueFlowForwardAssign(Token * const tok,
|
||||||
ErrorLogger * const errorLogger,
|
ErrorLogger * const errorLogger,
|
||||||
const Settings * const settings)
|
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))) {
|
if (std::any_of(values.begin(), values.end(), std::mem_fn(&ValueFlow::Value::isLifetimeValue))) {
|
||||||
valueFlowForwardLifetime(tok, tokenlist, errorLogger, settings);
|
valueFlowForwardLifetime(tok, tokenlist, errorLogger, settings);
|
||||||
values.remove_if(std::mem_fn(&ValueFlow::Value::isLifetimeValue));
|
values.remove_if(std::mem_fn(&ValueFlow::Value::isLifetimeValue));
|
||||||
|
|
|
@ -2034,6 +2034,19 @@ private:
|
||||||
"}\n";
|
"}\n";
|
||||||
ASSERT_EQUALS(false, testValueOfX(code, 6U, 3));
|
ASSERT_EQUALS(false, testValueOfX(code, 6U, 3));
|
||||||
TODO_ASSERT_EQUALS(true, false, testValueOfX(code, 6U, 2));
|
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() {
|
void valueFlowAfterCondition() {
|
||||||
|
|
Loading…
Reference in New Issue