Rule A5-2-6 (required, implementation, automated)
The operands of a logical && or \ shall be parenthesized if the operands contain binary operators.
Rationale
Parentheses are required to add clarity in logical expressions making code easier to review versus code based only C++ operator precedence rules.
Example
// $Id: A5-2-6.cpp$
#include <cstdint>
void Fn(std::int32_t value) noexcept
{
if (value > 0 && value < 3) // Non-compliant
{
// do some work
}
else if ((value > 1) && (value < 2)) // Compliant
{
// do some work
}
else
{
// do some work
}
return;
}
See also
MISRA C++ 2008 [7]: M5-2-1: Each operand of a logical && or || shall be a postfix expression. JSF December 2005 [8]: AV Rule 158: The operands of a logical && or \ shall be parenthesized if the operands contain binary operators. C++ Core Guidelines [11]: ES.41: If in doubt about operator precedence, parenthesize