MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / checkComparisonOfBoolWithBool

Method checkComparisonOfBoolWithBool

lib/checkbool.cpp:264–303  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

262//-------------------------------------------------------------------------------
263
264void CheckBoolImpl::checkComparisonOfBoolWithBool()
265{
266 if (!mSettings.severity.isEnabled(Severity::style))
267 return;
268
269 if (!mTokenizer->isCPP())
270 return;
271
272 logChecker("CheckBool::checkComparisonOfBoolWithBool"); // style,c++
273
274 const SymbolDatabase* const symbolDatabase = mTokenizer->getSymbolDatabase();
275
276 for (const Scope * scope : symbolDatabase->functionScopes) {
277 for (const Token* tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) {
278 if (!tok->isComparisonOp() || tok->str() == "==" || tok->str() == "!=")
279 continue;
280 bool firstTokenBool = false;
281
282 const Token *firstToken = tok->previous();
283 if (firstToken->varId()) {
284 if (isBool(firstToken->variable())) {
285 firstTokenBool = true;
286 }
287 }
288 if (!firstTokenBool)
289 continue;
290
291 bool secondTokenBool = false;
292 const Token *secondToken = tok->next();
293 if (secondToken->varId()) {
294 if (isBool(secondToken->variable())) {
295 secondTokenBool = true;
296 }
297 }
298 if (secondTokenBool) {
299 comparisonOfBoolWithBoolError(firstToken->next(), secondToken->str());
300 }
301 }
302 }
303}
304
305void CheckBoolImpl::comparisonOfBoolWithBoolError(const Token *tok, const std::string &expression)
306{

Callers 1

runChecksMethod · 0.45

Calls 6

isBoolFunction · 0.85
isCPPMethod · 0.80
nextMethod · 0.80
variableMethod · 0.80
isEnabledMethod · 0.45
strMethod · 0.45

Tested by

no test coverage detected