diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 69cebc518..24c059081 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -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); }); diff --git a/test/teststl.cpp b/test/teststl.cpp index ac0d38de4..97b7b8194 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -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;\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() {