27-10-2023, 03:39 PM
Your static analyser is strictly correct in flagging a violation in your example. "case-clause” is the case label and associated code.
The rule as written was considering a switch with a single case-label and default. However, as your example illustrates, if you have multiple values to test, the switch statement is clearer than the if. This has been recognized and would be accepted as grounds for a deviation. Indeed, you may find that your static analyser has a flag that prevents it raising violations in code like your example.
The rule as written was considering a switch with a single case-label and default. However, as your example illustrates, if you have multiple values to test, the switch statement is clearer than the if. This has been recognized and would be accepted as grounds for a deviation. Indeed, you may find that your static analyser has a flag that prevents it raising violations in code like your example.
Posted by and on behalf of
the MISRA C++ Working Group
the MISRA C++ Working Group