Rule Definition
The use of operands with types other than bool with these(!, &&, ||) operators is unlikely to be meaningful (or intended). This rule allows the detection of such uses, which often occur because the logical operators (&&, || and !) can be easily confused with the bitwise operators (&, | and ~).
Remediation
Ensure to have boolean operands with boolean operators
Violation Code Sample
if ( 1 && ( c < d ) ) // Non-compliant
if ( ( a < b ) && ( c + d ) ) // Non-compliant
if ( u8_a && ( c + d ) ) // Non-compliant
if ( !0 ) // Non-compliant
if ( !ptr ) // Non-compliant
Fixed Code Sample
if ( ( a < b ) && ( c < d ) ) // Compliant
Reference
MISRA C++, 5-3-1: Each operand of the ! operator, the logical && or the logical || operators shall have type bool.
AUTOSAR, C++, 2014, Rule M5-3-1: Each operand of the ! operator, the logical && or the logical || operators shall have type bool.
Related Technologies
Technical Criterion
Programming Practices - Unexpected Behavior
About CAST Appmarq
CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.