Skip to content

Commit 0089f5a

Browse files
Update checkstl.cpp
1 parent 06e7663 commit 0089f5a

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

lib/checkstl.cpp

+10-1
Original file line numberDiff line numberDiff line change
@@ -2904,6 +2904,13 @@ void CheckStl::useStlAlgorithm()
29042904
return false;
29052905
return isConstExpression(tok->linkAt(-1)->astOperand2(), mSettings->library);
29062906
};
2907+
2908+
auto isAccumulation = [](const Token* tok, int varId) {
2909+
if (tok->str() != "=")
2910+
return true;
2911+
const Token* end = Token::findmatch(tok, "%varid%|;", varId); // TODO: lambdas?
2912+
return end && end->varId() != 0;
2913+
};
29072914

29082915
for (const Scope *function : mTokenizer->getSymbolDatabase()->functionScopes) {
29092916
for (const Token *tok = function->bodyStart; tok != function->bodyEnd; tok = tok->next()) {
@@ -2970,8 +2977,10 @@ void CheckStl::useStlAlgorithm()
29702977
algo = "std::any_of, std::all_of, std::none_of, or std::accumulate";
29712978
else if (Token::Match(assignTok, "= %var% <|<=|>=|> %var% ? %var% : %var%") && hasVarIds(assignTok->tokAt(6), loopVar->varId(), assignVarId))
29722979
algo = minmaxCompare(assignTok->tokAt(2), loopVar->varId(), assignVarId, assignTok->tokAt(5)->varId() == assignVarId);
2973-
else
2980+
else if (isAccumulation(assignTok, assignVarId))
29742981
algo = "std::accumulate";
2982+
else
2983+
continue;
29752984
}
29762985
useStlAlgorithmError(assignTok, algo);
29772986
continue;

0 commit comments

Comments
 (0)