Fix issue 9899: False positive: Non-local variable will use object that points to local variable (#2808)
This commit is contained in:
parent
3459f0da32
commit
ebbff08932
|
@ -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));
|
||||
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in New Issue