@@ -3340,14 +3340,15 @@ static std::vector<LifetimeToken> getLifetimeTokens(const Token* tok,
33403340 return {{tok, std::move (errorPath)}};
33413341 if (var && var->declarationId () == tok->varId ()) {
33423342 if (var->isReference () || var->isRValueReference ()) {
3343- if (!var->declEndToken ())
3343+ const Token * const varDeclEndToken = var->declEndToken ();
3344+ if (!varDeclEndToken)
33443345 return {{tok, true , std::move (errorPath)}};
33453346 if (var->isArgument ()) {
3346- errorPath.emplace_back (var-> declEndToken () , " Passed to reference." );
3347+ errorPath.emplace_back (varDeclEndToken , " Passed to reference." );
33473348 return {{tok, true , std::move (errorPath)}};
3348- } else if (Token::simpleMatch (var-> declEndToken () , " =" )) {
3349- errorPath.emplace_back (var-> declEndToken () , " Assigned to reference." );
3350- const Token *vartok = var-> declEndToken () ->astOperand2 ();
3349+ } else if (Token::simpleMatch (varDeclEndToken , " =" )) {
3350+ errorPath.emplace_back (varDeclEndToken , " Assigned to reference." );
3351+ const Token *vartok = varDeclEndToken ->astOperand2 ();
33513352 const bool temporary = isTemporary (true , vartok, nullptr , true );
33523353 const bool nonlocal = var->isStatic () || var->isGlobal ();
33533354 if (vartok == tok || (nonlocal && temporary) ||
@@ -4021,6 +4022,8 @@ struct LifetimeStore {
40214022 return ;
40224023 if (!argtok)
40234024 return ;
4025+ if (!tok)
4026+ return ;
40244027 for (const ValueFlow::Value &v : argtok->values ()) {
40254028 if (!v.isLifetimeValue ())
40264029 continue ;
@@ -4031,7 +4034,8 @@ struct LifetimeStore {
40314034 er.insert (er.end (), errorPath.begin (), errorPath.end ());
40324035 if (!var)
40334036 continue ;
4034- for (const Token *tok3 = tok; tok3 && tok3 != var->declEndToken (); tok3 = tok3->previous ()) {
4037+ const Token * const varDeclEndToken = var->declEndToken ();
4038+ for (const Token *tok3 = tok; tok3 && tok3 != varDeclEndToken; tok3 = tok3->previous ()) {
40354039 if (tok3->varId () == var->declarationId ()) {
40364040 LifetimeStore{tok3, message, type, inconclusive}.byVal (tok, tokenlist, errorLogger, settings, pred);
40374041 break ;
0 commit comments