MISRA C++:2008 Rule 5-8-1
The right hand operand of a shift operator shall lie between zero and one less than the width in bits of the underlying type of the left hand operand
Description
Rule Definition
The right hand operand of a shift operator shall lie between zero and one less than the width in bits of the underlying type of the left hand operand.
Rationale
When you use a shift operator, the value of the right-hand operand must be:
Greater than or equal to zero.
Less than the bit size of the data type of the left-hand operand.
If the above is not true, using a shift operator results in undefined behavior, which makes your program unpredictable and yields unexpected results.
Polyspace Implementation
Polyspace® reports a rule violation when you use a negative operand on the right-hand side of a shift operator. Polyspace also reports a violation when the right-hand side of a shift operator is at least as large as the bit size of the data type of the left-hand operand.
Troubleshooting
If you expect a rule violation but Polyspace does not report it, see Diagnose Why Coding Standard Violations Do Not Appear as Expected.
Examples
Check Information
Group: Expressions |
Category: Required |
Version History
Introduced in R2013b