| 528 | } |
| 529 | |
| 530 | void 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 | |
| 573 | void CheckConditionImpl::overlappingElseIfConditionError(const Token *tok, nonneg int line1) |
| 574 | { |
no test coverage detected