MISRA C:2012 Rule 14.3

Controlling expressions shall not be invariant

Description

Rule Definition

Controlling expressions shall not be invariant.

Rationale

If the controlling expression, for example an if condition, has a constant value, the non-changing value can point to a programming error.

Polyspace Implementation

The checker flags conditions in if or while statements or conditions that appear as the first operands of ternary operators (?:) if the conditions are invariant, for instance, evaluate always to true or false.

Polyspace® Bug Finder™ and Polyspace Code Prover™ check this coding rule differently. The analyses can produce different results.

Polyspace Bug Finder flags some violations of MISRA C® 14.3 through the Dead code and Useless if checkers.

Polyspace Code Prover does not use gray code to flag MISRA C 14.3 violations. In Code Prover, you can also see a difference in results based on your choice for the option Verification level (-to) (Polyspace Code Prover). See Check for Coding Standard Violations.

Additional Message in Report

  • Boolean operations whose results are invariant shall not be permitted.

  • Expression is always true.

  • Expression is always false.

  • Controlling expressions shall not be invariant.

Troubleshooting

If you expect a rule violation but do not see it, refer to Coding Standard Violations Not Displayed.

Check Information

Group: Control Statement Expressions
Category: Required
AGC Category: Required