C and C++


LANG.STRUCT.SW.MPC : caseの位置ずれ

要旨

case または defaultラベルに対する最も密に囲まれている ステートメントが、switch ステートメント本体ではありません。

このワーニングクラスは、 正しく記述されていないswitch文 の完全なサブセットです。

switchステートメントが、 以下のリストにある問題を複数提示する場合、解析結果としては、 その中から1つのみがレポートされます。

プロパティ

クラス名 Misplaced case
日本語クラス名 caseの位置ずれ
クラス分類 スタイル (style)
ニーモニック LANG.STRUCT.SW.MPC
カテゴリー
MisraC2023 MisraC2023:16.2 A switch label shall only be used when the most closely-enclosing compound statement is the body of a switch statement
Misra2012 Misra2012:16.2 A switch label shall only be used when the most closely-enclosing compound statement is the body of a switch statement
Misra2004 Misra2004:15.1 A switch label shall only be used when the most closely-enclosing compound statement is the body of a switch statement
AUTOSARC++14 AUTOSARC++14:M6-4-4 A switch-label shall only be used when the most closely-enclosing compound statement is the body of a switch statement.
MisraC++2008 MisraC++2008:6-4-4 A switch-label shall only be used when the most closely-enclosing compound statement is the body of a switch statement.
MisraC++2023 MisraC++2023:9.4.2 The structure of a switch statement shall be appropriate
CERT-C CERT-C:MSC20-C Do not use a switch statement to transfer control into a complex block
対応言語 C および C++ で利用可能です。
有効/無効設定 このワーニングクラスのチェックはデフォルトで無効になっており、プロジェクトには非正規の C向けAST が必要になります。有効にするにはプロジェクト設定ファイル (configuration file) に以下の WARNING_FILTER ルールと RETAIN_UNNORMALIZED_C_AST 設定を追加してください。
RETAIN_UNNORMALIZED_C_AST = Yes
WARNING_FILTER += allow class="Misplaced case"
注:非正規化された AST を継続して使用した場合、使用ディスク容量が増加し解析時間が長くなる可能性があります。

void lang_struct_sw_mpc (int i){
    switch (i){
        case 1: {                             /* most-closely enclosing statement is switch body*/
            /* ... */
            case 2: {          /* 'Misplaced case' warning issued here */
                    /* ... */
                    break;
                }
            }
        case 3: {/* ... */ break;}           /* most-closely enclosing statement is switch body */     
        case 4: {                            /* most-closely enclosing statement is switch body */
            /* ... */ 
            default: break;    /* 'Misplaced case' warning issued here */
        }
    }
}

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

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