Fix 10264: FP invalidContainer when address of container is passed inside struct (#3368)
This commit is contained in:
parent
9d51b4450b
commit
6a81b4c17c
|
@ -3515,13 +3515,13 @@ static void valueFlowLifetimeConstructor(Token* tok, TokenList* tokenlist, Error
|
|||
// Assume range constructor if passed a pair of iterators
|
||||
if (astIsContainer(parent) && args.size() == 2 && astIsIterator(args[0]) && astIsIterator(args[1])) {
|
||||
LifetimeStore::forEach(
|
||||
args, "Passed to initializer list.", ValueFlow::Value::LifetimeKind::Object, [&](const LifetimeStore& ls) {
|
||||
args, "Passed to initializer list.", ValueFlow::Value::LifetimeKind::SubObject, [&](const LifetimeStore& ls) {
|
||||
ls.byDerefCopy(tok, tokenlist, errorLogger, settings);
|
||||
});
|
||||
} else {
|
||||
LifetimeStore::forEach(args,
|
||||
"Passed to initializer list.",
|
||||
ValueFlow::Value::LifetimeKind::Object,
|
||||
ValueFlow::Value::LifetimeKind::SubObject,
|
||||
[&](const LifetimeStore& ls) {
|
||||
ls.byVal(tok, tokenlist, errorLogger, settings);
|
||||
});
|
||||
|
|
|
@ -4768,6 +4768,22 @@ private:
|
|||
" Parse(i);\n"
|
||||
"}\n",true);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("void f() {\n"
|
||||
" std::string x;\n"
|
||||
" struct V {\n"
|
||||
" std::string* pStr{};\n"
|
||||
" };\n"
|
||||
" struct I {\n"
|
||||
" std::vector<V> v;\n"
|
||||
" };\n"
|
||||
" I b[] = {{{{ &x }}}};\n"
|
||||
" x = \"Arial\";\n"
|
||||
" I cb[1];\n"
|
||||
" for (long i = 0; i < 1; ++i)\n"
|
||||
" cb[i] = b[i];\n"
|
||||
"}\n",true);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void invalidContainerLoop() {
|
||||
|
|
Loading…
Reference in New Issue