| 3442 | } |
| 3443 | |
| 3444 | void CheckOtherImpl::checkNegativeBitwiseShift() |
| 3445 | { |
| 3446 | const bool portability = mSettings.severity.isEnabled(Severity::portability); |
| 3447 | |
| 3448 | logChecker("CheckOther::checkNegativeBitwiseShift"); |
| 3449 | |
| 3450 | for (const Token* tok = mTokenizer->tokens(); tok; tok = tok->next()) { |
| 3451 | tok = skipUnreachableBranch(tok); |
| 3452 | |
| 3453 | if (!tok->astOperand1() || !tok->astOperand2()) |
| 3454 | continue; |
| 3455 | |
| 3456 | if (!Token::Match(tok, "<<|>>|<<=|>>=")) |
| 3457 | continue; |
| 3458 | |
| 3459 | // don't warn if lhs is a class. this is an overloaded operator then |
| 3460 | if (tok->isCpp()) { |
| 3461 | const ValueType * lhsType = tok->astOperand1()->valueType(); |
| 3462 | if (!lhsType || !lhsType->isIntegral() || lhsType->pointer) |
| 3463 | continue; |
| 3464 | } |
| 3465 | |
| 3466 | // bailout if operation is protected by ?: |
| 3467 | bool ternary = false; |
| 3468 | for (const Token *parent = tok; parent; parent = parent->astParent()) { |
| 3469 | if (Token::Match(parent, "?|:")) { |
| 3470 | ternary = true; |
| 3471 | break; |
| 3472 | } |
| 3473 | } |
| 3474 | if (ternary) |
| 3475 | continue; |
| 3476 | |
| 3477 | // Get negative rhs value. preferably a value which doesn't have 'condition'. |
| 3478 | if (portability && isNegative(tok->astOperand1(), mSettings)) |
| 3479 | negativeBitwiseShiftError(tok, 1); |
| 3480 | else if (isNegative(tok->astOperand2(), mSettings)) |
| 3481 | negativeBitwiseShiftError(tok, 2); |
| 3482 | } |
| 3483 | } |
| 3484 | |
| 3485 | |
| 3486 | void CheckOtherImpl::negativeBitwiseShiftError(const Token *tok, int op) |
no test coverage detected