@@ -2870,30 +2870,30 @@ static void valueFlowLifetimeClassConstructor(Token* tok,
28702870 " Passed to constructor of '" + t->name () + " '." ,
28712871 ValueFlow::Value::LifetimeKind::SubObject,
28722872 [&](LifetimeStore &ls)
2873+ {
2874+ // Skip static variable
2875+ it = std::find_if (it, scope->varlist .cend (), [&](const Variable &var)
2876+ { return !var.isStatic () && (!hasDesignatedInitializers || var.name () == ls.argtok ->astOperand1 ()->astOperand1 ()->str ()); });
2877+ if (it == scope->varlist .cend ())
2878+ return ;
2879+ if (hasDesignatedInitializers)
2880+ ls.argtok = ls.argtok ->astOperand2 ();
2881+ const Variable &var = *it;
2882+ if (var.valueType () && var.valueType ()->container && var.valueType ()->container ->stdStringLike && !var.valueType ()->container ->view )
2883+ return ; // TODO: check in isLifetimeBorrowed()?
2884+ if (var.isReference () || var.isRValueReference ())
28732885 {
2874- // Skip static variable
2875- it = std::find_if (it, scope->varlist .cend (), [&](const Variable &var)
2876- { return !var.isStatic () && (!hasDesignatedInitializers || var.name () == ls.argtok ->astOperand1 ()->astOperand1 ()->str ()); });
2877- if (it == scope->varlist .cend ())
2878- return ;
2879- if (hasDesignatedInitializers)
2880- ls.argtok = ls.argtok ->astOperand2 ();
2881- const Variable &var = *it;
2882- if (var.valueType () && var.valueType ()->container && var.valueType ()->container ->stdStringLike && !var.valueType ()->container ->view )
2883- return ; // TODO: check in isLifetimeBorrowed()?
2884- if (var.isReference () || var.isRValueReference ())
2885- {
2886- ls.byRef (tok, tokenlist, errorLogger, settings);
2887- }
2888- else if (ValueFlow::isLifetimeBorrowed (ls.argtok , settings))
2889- {
2890- ls.byVal (tok, tokenlist, errorLogger, settings);
2891- }
2892- if (hasDesignatedInitializers)
2893- it = scope->varlist .cbegin ();
2894- else
2895- it++;
2896- });
2886+ ls.byRef (tok, tokenlist, errorLogger, settings);
2887+ }
2888+ else if (ValueFlow::isLifetimeBorrowed (ls.argtok , settings))
2889+ {
2890+ ls.byVal (tok, tokenlist, errorLogger, settings);
2891+ }
2892+ if (hasDesignatedInitializers)
2893+ it = scope->varlist .cbegin ();
2894+ else
2895+ it++;
2896+ });
28972897 } else {
28982898 const Function* constructor = findConstructor (scope, tok, args);
28992899 valueFlowLifetimeUserConstructor (tok, constructor, t->name (), args, tokenlist, errorLogger, settings);
0 commit comments