MISRA C++:2023 Rule 7.0.3
Description
Rule Definition
The numerical value of a character shall not be used.
Rationale
When you assign an integer value to a char
in C++, how that value
is interpreted depends on implementation settings such as the system character encoding
or locale settings. To reliably check character attributes, such as whether a character
is lowercase or alphanumeric, use functions from the Standard Template Library (STL)
rather than perform arithmetic on character values directly. To work with the numeric
representation of characters, use the conversion functions provided by
std::char_traits<>
rather than manual conversions.
Polyspace Implementation
The rule checker reports a violation when the code uses the numerical value of a
character, including implicit and explicit conversions to or from
char
. The rule checker does not report a violation when:
A conversion function provided by
std::char_traits<>
performs the conversion.The numerical value of a character is used in an unevaluated context.
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: Standard Conversions |
Category: Required |
Version History
Introduced in R2024b