Skip to content

Commit c6daf43

Browse files
committed
Fix
1 parent e7e52bb commit c6daf43

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

lib/checkother.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1331,6 +1331,13 @@ static bool mayDependOn(const ValueType *other, const ValueType *original)
13311331
return otherPtr > originalPtr;
13321332
}
13331333

1334+
static bool isOnlyUsedInCurrentScope(const Variable* var, const Token *tok, const Scope* scope)
1335+
{
1336+
if (tok->scope() == scope)
1337+
return true;
1338+
return !Token::findmatch(tok->scope()->bodyEnd, "%varid%", scope->bodyEnd, var->declarationId());
1339+
}
1340+
13341341
bool CheckOther::checkInnerScope(const Token *tok, const Variable* var, bool& used) const
13351342
{
13361343
const Scope* scope = tok->next()->scope();
@@ -1370,7 +1377,8 @@ bool CheckOther::checkInnerScope(const Token *tok, const Variable* var, bool& us
13701377
if (tok == forHeadEnd)
13711378
forHeadEnd = nullptr;
13721379

1373-
if (loopVariable && noContinue && (tok->scope() == scope || tok->scope()->type != ScopeType::eSwitch) && !forHeadEnd && scope->type != ScopeType::eSwitch && Token::Match(tok, "%varid% =", var->declarationId())) { // Assigned in outer scope.
1380+
if (loopVariable && noContinue && !forHeadEnd && scope->type != ScopeType::eSwitch && Token::Match(tok, "%varid% =", var->declarationId()) &&
1381+
isOnlyUsedInCurrentScope(var, tok, scope)) { // Assigned in outer scope.
13741382
loopVariable = false;
13751383
std::pair<const Token*, const Token*> range = tok->next()->findExpressionStartEndTokens();
13761384
if (range.first)
@@ -1869,6 +1877,8 @@ void CheckOther::checkConstPointer()
18691877
continue;
18701878
if (!var->isLocal() && !var->isArgument())
18711879
continue;
1880+
if (var->isArgument() && var->scope() && var->scope()->type == ScopeType::eLambda)
1881+
continue;
18721882
const Token* const nameTok = var->nameToken();
18731883
if (tok == nameTok && var->isLocal() && !astIsRangeBasedForDecl(nameTok)) {
18741884
if (var->isReference() && var->isPointer()) {

0 commit comments

Comments
 (0)