C and C++


LANG.STRUCT.INIT.ENUM : 列挙子初期化の不適合

要旨

列挙の初期化宣言において、列挙子の初期化は以下のいずれかを要件としている JPL rule 12 に違反しています。

プロパティ

クラス名 Inconsistent Enumerator Initialization
日本語クラス名 列挙子初期化の不適合
クラス分類 スタイル (style)
ニーモニック LANG.STRUCT.INIT.ENUM
カテゴリー
MisraC2023 MisraC2023:8.12 Within an enumerator list, the value of an implicitly-specified enumeration constant shall be unique
Misra2012 Misra2012:8.12 Within an enumerator list, the value of an implicitly-specified enumeration constant shall be unique
Misra2004 Misra2004:9.3 In an enumerator list, the "=" construct shall not be used to explicitly initialise members other than the first, unless all items are explicitly initialised
AUTOSARC++14 AUTOSARC++14:A7-2-4 In an enumeration, either (1) none, (2) the first or (3) all enumerators shall be initialized.
MisraC++2008 MisraC++2008:8-5-3 In an enumerator list, the = construct shall not be used to explicitly initialize members other than the first, unless all items are explicitly initialized.
MisraC++2023 MisraC++2023:11.6.3 Within an enumerator list, the value of an implicitly-specified enumeration constant shall be unique
CWE CWE:665 Improper Initialization
  CWE:710 Improper Adherence to Coding Standards
CERT-C CERT-C:INT09-C Ensure enumeration constants map to unique values
JSF++ JSF++:145 In an enumerator list, the '=' construct shall not be used to explicitly initialize members other than the first, unless all items are explicitly initialized.
JPL JPL:12 Do not use selective value assignments to elements of an enum list.
対応言語 C および C++ で利用可能です。
有効/無効設定 このワーニングクラスのチェックはデフォルトで無効になっており、プロジェクトには非正規の C向けAST が必要になります。有効にするにはプロジェクト設定ファイル (configuration file) に以下の WARNING_FILTER ルールと RETAIN_UNNORMALIZED_C_AST 設定を追加してください。
RETAIN_UNNORMALIZED_C_AST = Yes
WARNING_FILTER += allow class="Inconsistent Enumerator Initialization"
注:非正規化された AST を継続して使用した場合、使用ディスク容量が増加し解析時間が長くなる可能性があります。

enum no_second_init { /* 'Inconsistent Enumerator Initialization' warning issued here */
   NO_SECOND_INIT1 = 0,
   NO_SECOND_INIT2, 
   NO_SECOND_INIT3 = 2
};

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

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