Skip to content

Commit c538bbd

Browse files
Update checkautovariables.cpp
1 parent bb5f483 commit c538bbd

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

lib/checkautovariables.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,8 @@ bool CheckAutoVariables::checkAutoVariableAssignment(const Token *expr, bool inc
394394

395395
void CheckAutoVariables::errorAutoVariableAssignment(const Token *tok, bool inconclusive)
396396
{
397+
diag(tok);
398+
397399
if (!inconclusive) {
398400
reportError(tok, Severity::error, "autoVariables",
399401
"Address of local auto-variable assigned to a function parameter.\n"
@@ -674,14 +676,15 @@ void CheckAutoVariables::checkVarLifetimeScope(const Token * start, const Token
674676
const Token* nextTok = nextAfterAstRightmostLeaf(tok->astTop());
675677
if (!nextTok)
676678
nextTok = tok->next();
677-
if (var && (!var->isLocal() || var->isStatic()) && !var->isArgument() && !(val.tokvalue && val.tokvalue->variable() && val.tokvalue->variable()->isStatic()) &&
679+
if (var && (!var->isLocal() || var->isStatic()) && (!var->isArgument() || var->isReference()) && !(val.tokvalue && val.tokvalue->variable() && val.tokvalue->variable()->isStatic()) &&
678680
!isVariableChanged(nextTok,
679681
tok->scope()->bodyEnd,
680682
var->valueType() ? var->valueType()->pointer : 0,
681683
var->declarationId(),
682684
var->isGlobal(),
683685
*mSettings)) {
684-
errorDanglngLifetime(tok2, &val, var->isLocal());
686+
if (!diag(tok2))
687+
errorDanglngLifetime(tok2, &val, var->isLocal());
685688
break;
686689
}
687690
}
@@ -823,8 +826,8 @@ void CheckAutoVariables::runChecks(const Tokenizer &tokenizer, ErrorLogger *erro
823826
{
824827
CheckAutoVariables checkAutoVariables(&tokenizer, &tokenizer.getSettings(), errorLogger);
825828
checkAutoVariables.assignFunctionArg();
826-
checkAutoVariables.checkVarLifetime();
827829
checkAutoVariables.autoVariables();
830+
checkAutoVariables.checkVarLifetime();
828831
}
829832

830833
void CheckAutoVariables::getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const

0 commit comments

Comments
 (0)