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

Method returnValueOfFunctionReturningBool

lib/checkbool.cpp:482–508  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

480}
481
482void CheckBoolImpl::returnValueOfFunctionReturningBool()
483{
484 if (!mSettings.severity.isEnabled(Severity::style))
485 return;
486
487 logChecker("CheckBool::returnValueOfFunctionReturningBool"); // style
488
489 const SymbolDatabase * const symbolDatabase = mTokenizer->getSymbolDatabase();
490
491 for (const Scope * scope : symbolDatabase->functionScopes) {
492 if (!(scope->function && Token::Match(scope->function->retDef, "bool|_Bool")))
493 continue;
494
495 for (const Token* tok = scope->bodyStart->next(); tok && (tok != scope->bodyEnd); tok = tok->next()) {
496 // Skip lambdas
497 const Token* tok2 = findLambdaEndToken(tok);
498 if (tok2)
499 tok = tok2;
500 else if (tok->scope() && tok->scope()->isClassOrStruct())
501 tok = tok->scope()->bodyEnd;
502 else if (Token::simpleMatch(tok, "return") && tok->astOperand1() &&
503 (tok->astOperand1()->getValueGE(2, mSettings) || tok->astOperand1()->getValueLE(-1, mSettings)) &&
504 !(tok->astOperand1()->astOperand1() && Token::Match(tok->astOperand1(), "&|%or%")))
505 returnValueBoolError(tok);
506 }
507 }
508}
509
510void CheckBoolImpl::returnValueBoolError(const Token *tok)
511{

Callers 1

runChecksMethod · 0.80

Calls 8

findLambdaEndTokenFunction · 0.85
nextMethod · 0.80
scopeMethod · 0.80
astOperand1Method · 0.80
getValueGEMethod · 0.80
getValueLEMethod · 0.80
simpleMatchFunction · 0.70
isEnabledMethod · 0.45

Tested by

no test coverage detected