Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
A5-2-6 about operands consisting of a sequence of only `&&` or `||`
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 ||?
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.
Posted by and on behalf of
the MISRA C++ Working Group

Forum Jump:

Users browsing this thread: 1 Guest(s)