MISRA Discussion Forums

Full Version: A5-2-6 about operands consisting of a sequence of only `&&` or `||`
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Quote:A5-2-6 (Required) : The operands of a logical && or \\ shall be parenthesized if the operands contain binary operators.

What about those cases whose oeprands consists of either a sequence of only logical && or ||?
Code:
void f()
{
    int a, b, c, d;
    if ((a < b) || (b < c) || (c < d)) // compliant or noncompliant
    {
    }
}
This should be a exceptional case for MISRA C++-2008 Rule 5-2-1 ( Each operand of a logical && or || shall be a postfix-expression ), does this exception apply for A5-2-6 either?
I certainly would agree. where it gets muddy is if mixing || and && operator, but for the same operator throughout the expression what you state makes perfest sense to me.
From the wording of the Autosar rule, you are right that additional parentheses are required.

However, Autosar inherited this rule from MISRA C++:2008 5-2-1, and in MISRA there was an explicit exception for sequences of && and || (but not a mixture).

This is being reviewed for the next version.