MISRA C++:2008 Rule 6-2-1
Assignment operators shall not be used in sub-expressions
Description
Rule Definition
Assignment operators shall not be used in sub-expressions.
Rationale
When used in a subexpression, assignment operators have side effects that are difficult to predict. These side effects might produce results contrary to developer expectations. This rule helps in avoiding confusion between the assignment operator (=) and the equal to operator (==). Do not use assignment operators in subexpressions.
Polyspace Implementation
Polyspace® raises this defect whenever a subexpression contains an assignment operator.
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: Statements |
Category: Required |
Version History
Introduced in R2013b