C and C++


LANG.STRUCT.SW.MPD : 不適切な位置のdefault節

要旨

switch 文は default ラベルを含んでいますが、switch 文内の 最初もしくは最後以外の箇所に default ラベルがあります。

このクラスは 正しく記述されていないswitch文 の部分集合となります。

switch 文が下記の複数のワーニングを含む場合、 その部分集合のみが表示される可能性があります。

プロパティ

クラス名 Misplaced default
日本語クラス名 不適切な位置のdefault節
クラス分類 スタイル (style)
ニーモニック LANG.STRUCT.SW.MPD
カテゴリー
MisraC2023 MisraC2023:16.5 A default label shall appear as either the first or the last switch label of a switch statement
Misra2012 Misra2012:16.5 A default label shall appear as either the first or the last switch label of a switch statement
Misra2004 Misra2004:15.3 The final clause of a switch statement shall be the default clause
AUTOSARC++14 AUTOSARC++14:M6-4-6 The final clause of a switch statement shall be the default-clause.
MisraC++2008 MisraC++2008:6-4-6 The final clause of a switch statement shall be the default-clause.
MisraC++2023 MisraC++2023:9.4.2 The structure of a switch statement shall be appropriate
JSF++ JSF++:194 All switch statements that do not intend to test for every enumeration value shall contain a final default clause.
対応言語 C および C++ で利用可能です。
有効/無効設定 このワーニングクラスのチェックはデフォルトで無効になっており、プロジェクトには非正規の C向けAST が必要になります。有効にするにはプロジェクト設定ファイル (configuration file) に以下の WARNING_FILTER ルールと RETAIN_UNNORMALIZED_C_AST 設定を追加してください。
RETAIN_UNNORMALIZED_C_AST = Yes
WARNING_FILTER += allow class="Misplaced default"
注:非正規化された AST を継続して使用した場合、使用ディスク容量が増加し解析時間が長くなる可能性があります。

void lang_struct_sw_mpd(int i){

    switch (i){
        case 1:  {/* ... */ break;}
        case 2:  {/* ... */ break;}
        case 3: 
        default: {/* ... */ break;}                                /* default is last label */
    }

    switch (i){
        default:                                                   /* default is first label */
        case 1:  {/* ... */ break;}
        case 2:  {/* ... */ break;}
        case 3:  {/* ... */ break;}
    }

    switch (i){
        case 1: 
        default: {/* ... */ break;}    /* 'Misplaced default' warning issued here */
        case 2:  {/* ... */ break;}
        case 3:  {/* ... */ break;}
    }

    switch (i){
        case 1:  {/* ... */ break;}
        default:                       /* 'Misplaced default' warning issued here */
        case 2:  {/* ... */ break;}
        case 3:  {/* ... */ break;}
    }

    switch (i){
        case 1:  {/* ... */ break;}
        case 2:  {/* ... */ break;}
        default:                       /* 'Misplaced default' warning issued here */
        case 3:  {/* ... */ break;}
    }

}

関連のある設定ファイルパラメータ

設定ファイルの以下のパラメータがこのワーニングクラスのチェックに影響します。