@@ -4256,28 +4256,33 @@ struct LifetimeStore {
42564256 }
42574257};
42584258
4259- static bool isOwningVariables (const std::list<Variable>& vars, int depth = 10 )
4259+ static bool hasBorrowingVariables (const std::list<Variable>& vars, const std::vector< const Token*>& args , int depth = 10 )
42604260{
42614261 if (depth < 0 )
42624262 return false ;
4263- return vars.empty () || std::all_of (vars.cbegin (), vars.cend (), [&](const Variable& var) {
4264- if (var.isReference () || var.isPointer ())
4265- return false ;
4263+ return std::any_of (vars.cbegin (), vars.cend (), [&](const Variable& var) {
42664264 const ValueType* vt = var.valueType ();
42674265 if (vt) {
4268- if (vt->pointer > 0 )
4266+ if (vt->pointer > 0 &&
4267+ std::none_of (args.begin (), args.end (), [vt](const Token* arg) {
4268+ return arg->valueType () && arg->valueType ()->type == vt->type ;
4269+ }))
42694270 return false ;
4270- if (vt->isPrimitive () )
4271+ if (vt->pointer > 0 )
42714272 return true ;
4272- if (vt->isEnum () )
4273+ if (vt->reference != Reference::None )
42734274 return true ;
4275+ if (vt->isPrimitive ())
4276+ return false ;
4277+ if (vt->isEnum ())
4278+ return false ;
42744279 // TODO: Check container inner type
42754280 if (vt->type == ValueType::CONTAINER && vt->container )
4276- return ! vt->container ->view ;
4281+ return vt->container ->view ;
42774282 if (vt->typeScope )
4278- return isOwningVariables (vt->typeScope ->varlist , depth - 1 );
4283+ return hasBorrowingVariables (vt->typeScope ->varlist , args , depth - 1 );
42794284 }
4280- return false ;
4285+ return true ;
42814286 });
42824287}
42834288
@@ -4354,7 +4359,7 @@ static void valueFlowLifetimeUserConstructor(Token* tok,
43544359 else
43554360 ls.byVal (tok, tokenlist, errorLogger, settings);
43564361 });
4357- } else if (! isOwningVariables (constructor->nestedIn ->varlist )) {
4362+ } else if (hasBorrowingVariables (constructor->nestedIn ->varlist , args )) {
43584363 LifetimeStore::forEach (args,
43594364 " Passed to constructor of '" + name + " '." ,
43604365 ValueFlow::Value::LifetimeKind::SubObject,
0 commit comments