AutosarC++17_03-M5.0.21

Bitwise operators shall only be applied to operands of unsigned underlying type

Required inputs: IR

[Implementation 5.8(3)]
Rationale

Bitwise operations (~, <<, <<=, >>, >>=, &, &=, ^, ^=, | and |=) are not normally meaningful on signed integers or enumeration constants. Additionally, an implementation-defined result is obtained if a right shift is applied to a negative value.

Example
if ( ( uint16_a & int16_b  ) == 0x1234U )   // Non-compliant 
if ( ( uint16_a | uint16_b ) == 0x1234U ) // Compliant
if ( ~int16_a == 0x1234U ) // Non-compliant
if ( ~uint16_a == 0x1234U ) // Compliant

Note

For legal reasons, this rule’s description is not part of the public documentation.