C and C++


LANG.PREPROC.UNDEFINFN : 関数内でのマクロ無効化

要旨

関数内でマクロが(#undefで)無効化されています。

プロパティ

クラス名 Macro Undefined in Function Body
日本語クラス名 関数内でのマクロ無効化
クラス分類 スタイル (style)
ニーモニック LANG.PREPROC.UNDEFINFN
カテゴリー
Misra2004 Misra2004:19.5 Macros shall not be #define'd or #undef'd within a block
AUTOSARC++14 AUTOSARC++14:A16-0-1 The pre-processor shall only be used for unconditional and conditional file inclusion and include guards, and using the following directives: (1) #ifndef, (2) #ifdef, (3) #if, (4) #if defined, (5) #elif, (6) #else, (7) #define, (8) #endif, (9) #include.
CWE CWE:710 Improper Adherence to Coding Standards
JPL JPL:21 Do not define macros within a function or a block.
対応言語 C および C++ で利用可能です。
有効/無効設定 このワーニングクラスのチェックはデフォルトで無効になっており、プロジェクトには非正規の C向けAST が必要になります。有効にするにはプロジェクト設定ファイル (configuration file) に以下の WARNING_FILTER ルールと RETAIN_UNNORMALIZED_C_AST 設定を追加してください。
RETAIN_UNNORMALIZED_C_AST = Yes
WARNING_FILTER += allow class="Macro Undefined in Function Body"
注:非正規化された AST を継続して使用した場合、使用ディスク容量が増加し解析時間が長くなる可能性があります。

#define CLEAR 1

int lang_preproc_undefinfn(void){
  /* 'Macro Undefined in Function Body' warning issued on following line */ 
#undef CLEAR
    return 0;
}

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

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