From 3615eac347d0b35497efb7183fd20c0ea68c7f54 Mon Sep 17 00:00:00 2001 From: Paul Fultz II Date: Fri, 15 Mar 2019 00:15:56 -0500 Subject: [PATCH] Move useStlAlgorithm to normal checking (#1741) --- lib/checkstl.cpp | 9 ++++----- lib/checkstl.h | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/checkstl.cpp b/lib/checkstl.cpp index b6c981427..2a44904a7 100644 --- a/lib/checkstl.cpp +++ b/lib/checkstl.cpp @@ -1877,7 +1877,7 @@ static const Token *singleAssignInScope(const Token *start, unsigned int varid, return nullptr; if (isVariableChanged(assignTok->next(), endStatement, varid, false, nullptr, true)) return nullptr; - input = Token::findmatch(assignTok->next(), "%varid%", endStatement, varid); + input = Token::findmatch(assignTok->next(), "%varid%", endStatement, varid) || !Token::Match(start->next(), "%var% ="); return assignTok; } @@ -1957,8 +1957,7 @@ static bool addByOne(const Token *tok, unsigned int varid) static bool accumulateBoolLiteral(const Token *tok, unsigned int varid) { - // TODO: Missing %oreq% - if (Token::Match(tok, "=|&= %bool% ;") && + if (Token::Match(tok, "%assign% %bool% ;") && tok->tokAt(1)->hasKnownIntValue()) { return true; } @@ -1971,8 +1970,8 @@ static bool accumulateBoolLiteral(const Token *tok, unsigned int varid) static bool accumulateBool(const Token *tok, unsigned int varid) { - // TODO: Missing %oreq% - if (Token::simpleMatch(tok, "&=")) { + // Missing %oreq% so we have to check both manually + if (Token::simpleMatch(tok, "&=") || Token::simpleMatch(tok, "|=")) { return true; } if (Token::Match(tok, "= %varid% %oror%|%or%|&&|&", varid)) { diff --git a/lib/checkstl.h b/lib/checkstl.h index b3a8c267f..839406495 100644 --- a/lib/checkstl.h +++ b/lib/checkstl.h @@ -71,6 +71,7 @@ public: checkStl.redundantCondition(); checkStl.string_c_str(); checkStl.uselessCalls(); + checkStl.useStlAlgorithm(); } /** Simplified checks. The token list is simplified. */ @@ -88,7 +89,6 @@ public: // Style check checkStl.size(); - checkStl.useStlAlgorithm(); } /** Accessing container out of bounds using ValueFlow */