| 477 | } |
| 478 | |
| 479 | void 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 | |
| 518 | void CheckConditionImpl::duplicateConditionError(const Token *tok1, const Token *tok2, ErrorPath errorPath) |
| 519 | { |
no test coverage detected