AUTOSAR C++14 Rule A5-16-1
The ternary conditional operator shall not be used as a sub-expression
Description
Rule Definition
The ternary conditional operator shall not be used as a sub-expression.
Rationale
A ternary conditional operator used as a subexpression makes the full expression less readable and difficult to maintain. It is often visually clearer if you assign the result of a ternary operator to a variable and then use the variable in subsequent operations.
Polyspace Implementation
The checker flags uses of the ternary conditional operator in subexpressions with some exceptions. Exceptions include uses of the operator when:
The result is assigned to a variable.
The result is used as a function argument or returned from a function.
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, Automated |
Version History
Introduced in R2019b