MISRA C++:2023 Rule 0.0.2
Description
Rule Definition
Controlling expressions should not be invariant.
Rationale
If the controlling expression of an if
, for
, or while
statement has an invariant value, for instance, always evaluates to true or false, the expression is dead code that can be removed without any functional impact. Compilers can sometimes detect these invariant expressions and remove them from the final executable. These invariant expressions typically indicate a programming error and might lead to code inadvertently not
executing.
Polyspace Implementation
The rule checker reports violations if the controlling expression of statements such as if
, for
, or while
evaluate to a constant value.
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: Language Independent Issues |
Category: Advisory |
Version History
Introduced in R2024b