@@ -2697,6 +2697,7 @@ std::string lifetimeType(const Token *tok, const ValueFlow::Value *val)
26972697 result = " iterator" ;
26982698 break ;
26992699 case ValueFlow::Value::Object:
2700+ case ValueFlow::Value::Address:
27002701 if (astIsPointer (tok))
27012702 result = " pointer" ;
27022703 else
@@ -2706,6 +2707,26 @@ std::string lifetimeType(const Token *tok, const ValueFlow::Value *val)
27062707 return result;
27072708}
27082709
2710+ ValueFlow::Value getLifetimeObjValue (const Token *tok)
2711+ {
2712+ ValueFlow::Value result;
2713+ auto pred = [](const ValueFlow::Value &v) {
2714+ if (!v.isLocalLifetimeValue ())
2715+ return false ;
2716+ if (!v.tokvalue ->variable ())
2717+ return false ;
2718+ return true ;
2719+ };
2720+ auto it = std::find_if (tok->values ().begin (), tok->values ().end (), pred);
2721+ if (it == tok->values ().end ())
2722+ return result;
2723+ result = *it;
2724+ // There should only be one lifetime
2725+ if (std::find_if (std::next (it), tok->values ().end (), pred) != tok->values ().end ())
2726+ return result;
2727+ return result;
2728+ }
2729+
27092730static const Token *getLifetimeToken (const Token *tok, ValueFlow::Value::ErrorPath &errorPath, int depth = 20 )
27102731{
27112732 if (!tok)
@@ -3337,6 +3358,8 @@ static void valueFlowLifetime(TokenList *tokenlist, SymbolDatabase*, ErrorLogger
33373358 value.lifetimeScope = ValueFlow::Value::Local;
33383359 value.tokvalue = lifeTok;
33393360 value.errorPath = errorPath;
3361+ if (astIsPointer (lifeTok) || !Token::Match (lifeTok->astParent (), " .|[" ))
3362+ value.lifetimeKind = ValueFlow::Value::Address;
33403363 setTokenValue (tok, value, tokenlist->getSettings ());
33413364
33423365 valueFlowForwardLifetime (tok, tokenlist, errorLogger, settings);
0 commit comments