Fix 10264: FP invalidContainer when address of container is passed inside struct (#3286)
This commit is contained in:
parent
b23c5aa742
commit
537fb5bcd9
|
@ -3499,7 +3499,7 @@ static void valueFlowLifetimeConstructor(Token* tok,
|
||||||
// constructor, but make each lifetime inconclusive
|
// constructor, but make each lifetime inconclusive
|
||||||
std::vector<const Token*> args = getArguments(tok);
|
std::vector<const Token*> args = getArguments(tok);
|
||||||
LifetimeStore::forEach(
|
LifetimeStore::forEach(
|
||||||
args, "Passed to initializer list.", ValueFlow::Value::LifetimeKind::Object, [&](LifetimeStore& ls) {
|
args, "Passed to initializer list.", ValueFlow::Value::LifetimeKind::SubObject, [&](LifetimeStore& ls) {
|
||||||
ls.inconclusive = true;
|
ls.inconclusive = true;
|
||||||
ls.byVal(tok, tokenlist, errorLogger, settings);
|
ls.byVal(tok, tokenlist, errorLogger, settings);
|
||||||
});
|
});
|
||||||
|
@ -3514,7 +3514,7 @@ static void valueFlowLifetimeConstructor(Token* tok,
|
||||||
auto it = scope->varlist.begin();
|
auto it = scope->varlist.begin();
|
||||||
LifetimeStore::forEach(args,
|
LifetimeStore::forEach(args,
|
||||||
"Passed to constructor of '" + t->name() + "'.",
|
"Passed to constructor of '" + t->name() + "'.",
|
||||||
ValueFlow::Value::LifetimeKind::Object,
|
ValueFlow::Value::LifetimeKind::SubObject,
|
||||||
[&](const LifetimeStore& ls) {
|
[&](const LifetimeStore& ls) {
|
||||||
if (it == scope->varlist.end())
|
if (it == scope->varlist.end())
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -4665,6 +4665,17 @@ private:
|
||||||
ASSERT_EQUALS(
|
ASSERT_EQUALS(
|
||||||
"[test.cpp:1] -> [test.cpp:2] -> [test.cpp:3] -> [test.cpp:7] -> [test.cpp:1] -> [test.cpp:4]: (error) Using iterator to local container 'v' that may be invalid.\n",
|
"[test.cpp:1] -> [test.cpp:2] -> [test.cpp:3] -> [test.cpp:7] -> [test.cpp:1] -> [test.cpp:4]: (error) Using iterator to local container 'v' that may be invalid.\n",
|
||||||
errout.str());
|
errout.str());
|
||||||
|
|
||||||
|
// #10264
|
||||||
|
check("void f(std::vector<std::string>& x) {\n"
|
||||||
|
" struct I {\n"
|
||||||
|
" std::vector<std::string> *px{};\n"
|
||||||
|
" };\n"
|
||||||
|
" I i = { &x };\n"
|
||||||
|
" x.clear();\n"
|
||||||
|
" Parse(i);\n"
|
||||||
|
"}\n",true);
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void invalidContainerLoop() {
|
void invalidContainerLoop() {
|
||||||
|
|
Loading…
Reference in New Issue