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

Method duplicateCondition

lib/checkcondition.cpp:479–516  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

477}
478
479void CheckConditionImpl::duplicateCondition()
480{
481 if (!mSettings.severity.isEnabled(Severity::style) && !mSettings.isPremiumEnabled("duplicateCondition"))
482 return;
483
484 logChecker("CheckCondition::duplicateCondition"); // style
485
486 const SymbolDatabase *const symbolDatabase = mTokenizer->getSymbolDatabase();
487
488 for (const Scope &scope : symbolDatabase->scopeList) {
489 if (scope.type != ScopeType::eIf)
490 continue;
491
492 const Token* tok2 = scope.classDef->next();
493 if (!tok2)
494 continue;
495 const Token* cond1 = tok2->astOperand2();
496 if (!cond1)
497 continue;
498 if (cond1->hasKnownIntValue())
499 continue;
500
501 tok2 = tok2->link();
502 if (!Token::simpleMatch(tok2, ") {"))
503 continue;
504 tok2 = tok2->linkAt(1);
505 if (!Token::simpleMatch(tok2, "} if ("))
506 continue;
507 const Token *cond2 = tok2->tokAt(2)->astOperand2();
508 if (!cond2)
509 continue;
510
511 ErrorPath errorPath;
512 if (!findExpressionChanged(cond1, scope.classDef->next(), cond2, mSettings) &&
513 isSameExpression(true, cond1, cond2, mSettings, true, true, &errorPath))
514 duplicateConditionError(cond1, cond2, std::move(errorPath));
515 }
516}
517
518void CheckConditionImpl::duplicateConditionError(const Token *tok1, const Token *tok2, ErrorPath errorPath)
519{

Callers 1

runChecksMethod · 0.45

Calls 10

findExpressionChangedFunction · 0.85
isSameExpressionFunction · 0.85
isPremiumEnabledMethod · 0.80
nextMethod · 0.80
astOperand2Method · 0.80
linkAtMethod · 0.80
simpleMatchFunction · 0.70
isEnabledMethod · 0.45
hasKnownIntValueMethod · 0.45
tokAtMethod · 0.45

Tested by

no test coverage detected