MISRA Discussion Forums

Full Version: 5-2-10 with non-arithmetic operators
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi!

The rule states 


Quote:The increment (++) and decrement (--) operators should not be mixed with other operators in an expression.


The code checker we employ also flags the usage of these operators in expressions that contain member-access operators, subscript operators, and the like.

The rationale and example appear to focus on other arithmetic operators, which makes sense.

Is this an oversight in the rule formulation (missing "arithmetic"), or is the following intentionally non-compliant with 5-2-10?

Code:
void foo()
{
    struct A { int b; };

    A a{0};

    a.b++; // Non-compliant

    int c[3] = {1, 2, 3};

    c[2]++; // Non-compliant

    A* const a_ptr = &a;

    a_ptr->b++; // Non-compliant
}

Thanks!
We agree, this rule only applies to 'arithmetic operators'