@@ -590,23 +590,23 @@ void CheckAutoVariables::returnReference()
590590
591591static bool isInScope (const Token * tok, const Scope * scope)
592592{
593- if (!tok)
593+ if (!tok)
594594 return false ;
595- if (!scope)
595+ if (!scope)
596596 return false ;
597597 const Variable * var = tok->variable ();
598- if (var && (var->isGlobal () || var->isStatic () || var->isExtern ()))
598+ if (var && (var->isGlobal () || var->isStatic () || var->isExtern ()))
599599 return false ;
600- if (tok->scope () && tok->scope ()->isNestedIn (scope))
600+ if (tok->scope () && tok->scope ()->isNestedIn (scope))
601601 return true ;
602- if (!var)
602+ if (!var)
603603 return false ;
604- if (var->isArgument () && !var->isReference ()) {
604+ if (var->isArgument () && !var->isReference ()) {
605605 const Scope * tokScope = tok->scope ();
606- if (!tokScope)
606+ if (!tokScope)
607607 return false ;
608- for (const Scope * argScope:tokScope->nestedList ) {
609- if (argScope && argScope->isNestedIn (scope))
608+ for (const Scope * argScope:tokScope->nestedList ) {
609+ if (argScope && argScope->isNestedIn (scope))
610610 return true ;
611611 }
612612 }
@@ -615,35 +615,35 @@ static bool isInScope(const Token * tok, const Scope * scope)
615615
616616void CheckAutoVariables::checkVarLifetimeScope (const Token * start, const Token * end)
617617{
618- if (!start)
618+ if (!start)
619619 return ;
620620 const Scope * scope = start->scope ();
621- if (!scope)
621+ if (!scope)
622622 return ;
623623 // If the scope is not set correctly then skip checking it
624- if (scope->bodyStart != start)
624+ if (scope->bodyStart != start)
625625 return ;
626626 for (const Token *tok = start; tok && tok != end; tok = tok->next ()) {
627627 // Skip duplicate warning from dangling references
628- if (Token::Match (tok, " & %var%" ))
628+ if (Token::Match (tok, " & %var%" ))
629629 continue ;
630- if (tok->variable () && tok->variable ()->isPointer ())
630+ if (tok->variable () && tok->variable ()->isPointer ())
631631 continue ;
632- if (std::any_of (tok->values ().begin (), tok->values ().end (), std::mem_fn (&ValueFlow::Value::isTokValue)))
632+ if (std::any_of (tok->values ().begin (), tok->values ().end (), std::mem_fn (&ValueFlow::Value::isTokValue)))
633633 continue ;
634634
635- for (const ValueFlow::Value& val:tok->values ()) {
636- if (!val.isLifetimeValue ())
635+ for (const ValueFlow::Value& val:tok->values ()) {
636+ if (!val.isLifetimeValue ())
637637 continue ;
638- if (Token::Match (tok->astParent (), " return|throw" )) {
638+ if (Token::Match (tok->astParent (), " return|throw" )) {
639639 if (isInScope (val.tokvalue , scope)) {
640640 errorReturnDanglingLifetime (tok, &val);
641641 break ;
642642 }
643643 }
644644 }
645645 const Token *lambdaEndToken = findLambdaEndToken (tok);
646- if (lambdaEndToken) {
646+ if (lambdaEndToken) {
647647 checkVarLifetimeScope (lambdaEndToken->link (), lambdaEndToken);
648648 tok = lambdaEndToken;
649649 }
@@ -669,31 +669,31 @@ void CheckAutoVariables::errorReturnDanglingLifetime(const Token *tok, const Val
669669 const Token *vartok = val->tokvalue ;
670670 ErrorPath errorPath = val->errorPath ;
671671 std::string msg = " " ;
672- switch (val->lifetimeKind ) {
673- case ValueFlow::Value::Object:
674- msg = " Returning object" ;
675- break ;
676- case ValueFlow::Value::Lambda:
677- msg = " Returning lambda" ;
678- break ;
679- case ValueFlow::Value::Iterator:
680- msg = " Returning iterator" ;
681- break ;
672+ switch (val->lifetimeKind ) {
673+ case ValueFlow::Value::Object:
674+ msg = " Returning object" ;
675+ break ;
676+ case ValueFlow::Value::Lambda:
677+ msg = " Returning lambda" ;
678+ break ;
679+ case ValueFlow::Value::Iterator:
680+ msg = " Returning iterator" ;
681+ break ;
682682 }
683- if (vartok) {
683+ if (vartok) {
684684 errorPath.emplace_back (vartok, " Variable created here." );
685685 const Variable * var = vartok->variable ();
686- if (var) {
687- switch (val->lifetimeKind ) {
688- case ValueFlow::Value::Object:
689- msg += " that points to local variable" ;
690- break ;
691- case ValueFlow::Value::Lambda:
692- msg += " that captures local variable" ;
693- break ;
694- case ValueFlow::Value::Iterator:
695- msg += " to local container" ;
696- break ;
686+ if (var) {
687+ switch (val->lifetimeKind ) {
688+ case ValueFlow::Value::Object:
689+ msg += " that points to local variable" ;
690+ break ;
691+ case ValueFlow::Value::Lambda:
692+ msg += " that captures local variable" ;
693+ break ;
694+ case ValueFlow::Value::Iterator:
695+ msg += " to local container" ;
696+ break ;
697697 }
698698 msg += " '" + var->name () + " '" ;
699699 }
0 commit comments