| 145 | //--------------------------------------------------------------------------- |
| 146 | |
| 147 | void CheckBoolImpl::checkComparisonOfBoolWithInt() |
| 148 | { |
| 149 | if (!mSettings.severity.isEnabled(Severity::warning) || !mTokenizer->isCPP()) |
| 150 | return; |
| 151 | |
| 152 | logChecker("CheckBool::checkComparisonOfBoolWithInt"); // warning,c++ |
| 153 | |
| 154 | const SymbolDatabase* const symbolDatabase = mTokenizer->getSymbolDatabase(); |
| 155 | for (const Scope * scope : symbolDatabase->functionScopes) { |
| 156 | for (const Token* tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) { |
| 157 | if (!tok->isComparisonOp() || !tok->isBinaryOp()) |
| 158 | continue; |
| 159 | const Token* const left = tok->astOperand1(); |
| 160 | const Token* const right = tok->astOperand2(); |
| 161 | if (left->isBoolean() && right->varId()) { // Comparing boolean constant with variable |
| 162 | if (tok->str() != "==" && tok->str() != "!=") { |
| 163 | comparisonOfBoolWithInvalidComparator(right, left->str()); |
| 164 | } |
| 165 | } else if (left->varId() && right->isBoolean()) { // Comparing variable with boolean constant |
| 166 | if (tok->str() != "==" && tok->str() != "!=") { |
| 167 | comparisonOfBoolWithInvalidComparator(right, left->str()); |
| 168 | } |
| 169 | } |
| 170 | } |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | void CheckBoolImpl::comparisonOfBoolWithInvalidComparator(const Token *tok, const std::string &expression) |
| 175 | { |
no test coverage detected