Rule c:S868 improvement

Rule ID: c:S868
Rule name: # Operands of “&&” and “||” should be primary (C) or postfix (C++) expressions

Is it possible to add configuration to this rule, which parts of this rule are valid and which are not?
It is great rule for operands like && and ||, but it brings unnecessary clutter to the code with rule for ! (second example):

if (x || y && z);                        // Noncompliant
if (x && !y);                            // Noncompliant

So I propose if you can add change option to this rule to be able to select which are active and which are not.

Hi @nikola,

Welcome to the community and thanks for the suggestion!

This rule is based on an old version of MISRA, that was clearly a bit over-cautious. Nowadays, even MISRA no longer encourages having parentheses around the “!” operator.

I cannot give you an exact ETA, but we intend to update this rule to follow more modern best practices, which will solve the false positive you mention.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.