MISRA Discussion Forums

Full Version: Rule 15.7 and empty else statements without "else if"
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
MISRA C 2012 Rule 15.7 states in the amplification that "The else statement shall contain at least either one side effect or a
comment." Does "The else statement" refers to any else statement or just the final else statement that is required
by the rule when there are one or more "else if" statements? Is the following example a violation of Rule 15.7 because the else
statement does not contain a side effect or comment or is it compliant because the else is not required by the rule?

typedef _Bool bool_t;
void foo(bool_t x);
void foo(bool_t x) {
    if (x) {
    else { }
"The else statement" refers to the final else statement in a "if .. else if" construct.

Rule 15.7 does not apply to the above example because there is no "if... else if" construct in the example. No comment or side effect is required in this case.