MISRA C++:2008 Rule 5-0-3
A cvalue expression shall not be implicitly converted to a different underlying type
Description
Rule Definition
A cvalue expression shall not be implicitly converted to a different underlying type.
Rationale
This rule ensures that the result of the expression does not overflow when converted to a different type.
Polyspace Implementation
Expressions flagged by this checker follow the detailed specifications for cvalue expressions from the MISRA™ C++ documentation.
The underlying data type of a cvalue expression is the widest of operand data
types in the expression. For instance, if you add two variables, one of type
int8_t
(typedef
for
char
) and another of type int32_t
(typedef
for int
), the addition has
underlying type int32_t
. If you assign the sum to a variable of
type int8_t
, the rule is violated.
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