C and C++


LANG.STRUCT.NOELSE : Missing Final else

Summary

An if statement has one or more else if clauses, but does not have a final else clause.

Properties

Class Name Missing Final else
Significance style
Mnemonic LANG.STRUCT.NOELSE
Categories
MisraC2023 MisraC2023:15.7 All if ... else if constructs shall be terminated with an else statement
Misra2012 Misra2012:15.7 All if ... else if constructs shall be terminated with an else statement
Misra2004 Misra2004:14.10 All if . else if constructs shall be terminated with an else clause
AUTOSARC++14 AUTOSARC++14:M6-4-2 All if ... else if constructs shall be terminated with an else clause.
MisraC++2008 MisraC++2008:6-4-2 All if ... else if constructs shall be terminated with an else clause.
MisraC++2023 MisraC++2023:9.4.1 All if ... else if constructs shall be terminated with an else statement
JSF++ JSF++:192 All if, else if constructs will contain either a final else clause or a comment indicating why a final else clause is not necessary.
Availability Available for C and C++.
Enabling Checks for this warning class are disabled by default, and require the unnormalized C ASTs for the project. To enable them, add the following WARNING_FILTER rule and RETAIN_UNNORMALIZED_C_AST specification to the project configuration file.
RETAIN_UNNORMALIZED_C_AST = Yes
WARNING_FILTER += allow class="Missing Final else"
Note that retaining the unnormalized ASTs will increase the disk space used to store the project representation, and may make the analysis take longer.

Example

int lang_struct_noelse(int i, int j){
    if (i==0)
        return 1;
    else if (i < 0) /* 'Missing Final Else' warning issued here */
        return 5;

    if (j==0)
        return 1;               /* ok: no ELSE IF clauses */

    return 6;
}

Relevant Configuration File Parameters

The following configuration file parameters affect checks for this warning class.