MISRA.CHAR.OPERANDExpression of type 'char' or 'wchar_t' is used as non-character operand. MISRA-C++ Rule 4-5-3 (required): Expressions with type (plain) char and wchar_t shall not be used as operands to built-in operators other than the assignment operator =, the equality operators == and !=, and the unary & operator.RationaleManipulation of character data may generate results that are contrary to developer expectations. For example, ISO/IEC 14882:2003 [1] §2.2(3) only requires that the digits "0" to "9" have consecutive numerical values. ExceptionExceptionally, the following operators may be used if the associated restriction is observed:
Examplechar_t ch = 't'; // Compliant uint8_t v; if ( ( ch >= 'a' ) && ( ch <= 'z' ) ) // Non-compliant { } if ( ( ch >= '0' ) && ( ch <= '9' ) ) // Compliant by exception { v = ch — '0'; // Compliant by exception v = ch — '1'; // Non-compliant } else { // ... } ch = '0' + v; // Compliant by exception ch = 'A' + v; // Non-compliant |