C and C++


LANG.STRUCT.MISRS : 不適切な位置のreturn文

要旨

return 文が関数の最後以外の位置に存在します。

プロパティ

クラス名 Misplaced Return Statement
日本語クラス名 不適切な位置のreturn文
クラス分類 スタイル (style)
ニーモニック LANG.STRUCT.MISRS
カテゴリー
MisraC2023 MisraC2023:15.5 A function should have a single point of exit at the end
Misra2012 Misra2012:15.5 A function should have a single point of exit at the end
Misra2004 Misra2004:14.7 A function shall have a single point of exit at the end of the function
MisraC++2008 MisraC++2008:6-6-5 A function shall have a single point of exit at the end of the function.
対応言語 C および C++ で利用可能です。
有効/無効設定 このワーニングクラスのチェックはデフォルトで無効になっており、プロジェクトには非正規の C向けAST が必要になります。有効にするにはプロジェクト設定ファイル (configuration file) に以下の WARNING_FILTER ルールと RETAIN_UNNORMALIZED_C_AST 設定を追加してください。
RETAIN_UNNORMALIZED_C_AST = Yes
WARNING_FILTER += allow class="Misplaced Return Statement"
注:非正規化された AST を継続して使用した場合、使用ディスク容量が増加し解析時間が長くなる可能性があります。

int lang_struct_misrs(int i){ /* 'Misplaced Return Statement' warning issued here. */
    int x=0;
    while (1){
        if (x >= i) return x;
        x++;
    }
}

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

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