MISRA C++:2008 Rule 5-0-9
An explicit integral conversion shall not change the signedness of the underlying type of a cvalue expression
Description
Rule Definition
An explicit integral conversion shall not change the signedness of the underlying type of a cvalue expression.1
Rationale
Expressions flagged by this checker follow the detailed specifications for cvalue expressions from the MISRA™ C++ documentation.
If you evaluate an expression and later cast the result to a different type, the
cast has no effect on the underlying type of the evaluation (the widest of operand
data types in the expression).. For instance, in this example, the sum of two
unsigned int
operands is cast to the type
int
.
unsigned int op1; unsigned int op2; int res; res= static_cast<int> (op1 + op2);
int
because of the later cast.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 R2013b1 All MISRA coding rules and directives are © Copyright The MISRA Consortium Limited 2021.
The MISRA coding standards referenced in the Polyspace Bug Finder™ documentation are from the following MISRA standards:
MISRA C:2004
MISRA C:2012
MISRA C:2023
MISRA C++:2008
MISRA C++:2023
MISRA and MISRA C are registered trademarks of The MISRA Consortium Limited 2021.