C and C++


LANG.STRUCT.SW.BAD : 正しく記述されていないswitch文

要旨

switch 文が以下のいずれかの問題を含んでいます。

このクラスは下記の各クラスの上位集合となります。

プロパティ

クラス名 Malformed switch Statement
日本語クラス名 正しく記述されていないswitch文
クラス分類 スタイル (style)
ニーモニック LANG.STRUCT.SW.BAD
カテゴリー
MisraC2023 MisraC2023:16.1 All switch statements shall be well-formed
Misra2012 Misra2012:16.1 All switch statements shall be well-formed
Misra2004 Misra2004:15.0 The MISRA C switch syntax shall be used
AUTOSARC++14 AUTOSARC++14:M6-4-3 A switch statement shall be a well-formed switch statement.
MisraC++2008 MisraC++2008:6-4-3 A switch statement shall be a well-formed switch statement.
MisraC++2023 MisraC++2023:9.4.2 The structure of a switch statement shall be appropriate
TS17961 TS17961:5.17-swtchdflt 5.17. Use of an implied default in a switch statement
CERT-C CERT-C:DCL41-C Do not declare variables inside a switch statement before the first case label
対応言語 C および C++ で利用可能です。
有効/無効設定 このワーニングクラスのチェックはデフォルトで無効になっており、プロジェクトには非正規の C向けAST が必要になります。有効にするにはプロジェクト設定ファイル (configuration file) に以下の WARNING_FILTER ルールと RETAIN_UNNORMALIZED_C_AST 設定を追加してください。
RETAIN_UNNORMALIZED_C_AST = Yes
WARNING_FILTER += allow class="Malformed switch Statement"
注:非正規化された AST を継続して使用した場合、使用ディスク容量が増加し解析時間が長くなる可能性があります。

void lang_struct_sw_bad(int i){

    switch(i){                                         /* has none of the listed issues */
        default: {/*...*/ break;}
        case 1:  {/*...*/ break;}
        case 2:  {/*...*/ break;}
        }

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

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


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

    switch(i%3){                    /* 'Malformed switch Statement' warning issued here */
                                    /* 'Empty switch Statement warning also issued */
        default :  {/*...*/ break;}
    }
}

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

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