MISRA Discussion Forums
A5-2-6 about operands consisting of a sequence of only `&&` or `||` - Printable Version

+- MISRA Discussion Forums (https://forum.misra.org.uk)
+-- Forum: MISRA C++ (https://forum.misra.org.uk/forumdisplay.php?fid=18)
+--- Forum: AUTOSAR C++:2014 rules (https://forum.misra.org.uk/forumdisplay.php?fid=185)
+--- Thread: A5-2-6 about operands consisting of a sequence of only `&&` or `||` (/showthread.php?tid=1631)



A5-2-6 about operands consisting of a sequence of only `&&` or `||` - zhaohui - 19-08-2022

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?


RE: A5-2-6 about operands consisting of a sequence of only `&&` or `||` - kent.dorfman766 - 25-08-2022

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.


RE: A5-2-6 about operands consisting of a sequence of only `&&` or `||` - misra cpp - 07-10-2022

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.