Fix issue 9899: False positive: Non-local variable will use object that points to local variable (#2808)

This commit is contained in:
Paul Fultz II 2020-09-15 00:11:52 -05:00 committed by GitHub
parent 3459f0da32
commit ebbff08932
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 0 deletions

View File

@ -5516,6 +5516,12 @@ static void valueFlowSubFunction(TokenList* tokenlist, SymbolDatabase* symboldat
// passing value(s) to function
std::list<ValueFlow::Value> argvalues(getFunctionArgumentValues(argtok));
// Remove non-local lifetimes
argvalues.remove_if([](const ValueFlow::Value& v) {
if (v.isLifetimeValue())
return !v.isLocalLifetimeValue() && !v.isSubFunctionLifetimeValue();
return false;
});
// Don't forward container sizes for now since programmemory can't evaluate conditions
argvalues.remove_if(std::mem_fn(&ValueFlow::Value::isContainerSizeValue));

View File

@ -2472,6 +2472,18 @@ private:
" return data;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
// #9899
check("struct A {\n"
" std::vector<int> v;\n"
" void f(std::vector<int> w) {\n"
" v = std::move(w);\n"
" }\n"
" void g(std::vector<int> w) {\n"
" f(std::move(w));\n"
" }\n"
"};\n");
ASSERT_EQUALS("", errout.str());
}
void danglingLifetimeFunction() {