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

Method multiCondition

lib/checkcondition.cpp:530–571  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

528}
529
530void CheckConditionImpl::multiCondition()
531{
532 if (!mSettings.severity.isEnabled(Severity::style) && !mSettings.isPremiumEnabled("multiCondition"))
533 return;
534
535 logChecker("CheckCondition::multiCondition"); // style
536
537 const SymbolDatabase* const symbolDatabase = mTokenizer->getSymbolDatabase();
538
539 for (const Scope &scope : symbolDatabase->scopeList) {
540 if (scope.type != ScopeType::eIf)
541 continue;
542
543 const Token * const cond1 = scope.classDef->next()->astOperand2();
544 if (!cond1)
545 continue;
546
547 const Token * tok2 = scope.classDef->next();
548
549 // Check each 'else if'
550 for (;;) {
551 tok2 = tok2->link();
552 if (!Token::simpleMatch(tok2, ") {"))
553 break;
554 tok2 = tok2->linkAt(1);
555 if (!Token::simpleMatch(tok2, "} else { if ("))
556 break;
557 tok2 = tok2->tokAt(4);
558
559 if (tok2->astOperand2()) {
560 ErrorPath errorPath;
561 if (isOverlappingCond(cond1, tok2->astOperand2(), true) &&
562 !findExpressionChanged(cond1, cond1, tok2->astOperand2(), mSettings))
563 overlappingElseIfConditionError(tok2->astOperand2(), cond1->linenr());
564 else if (isOppositeCond(
565 true, cond1, tok2->astOperand2(), mSettings, true, true, &errorPath) &&
566 !findExpressionChanged(cond1, cond1, tok2->astOperand2(), mSettings))
567 oppositeElseIfConditionError(cond1, tok2->astOperand2(), std::move(errorPath));
568 }
569 }
570 }
571}
572
573void CheckConditionImpl::overlappingElseIfConditionError(const Token *tok, nonneg int line1)
574{

Callers 1

runChecksMethod · 0.80

Calls 9

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

Tested by

no test coverage detected