C and C++


LANG.TYPE.BFSHORT : 短すぎるビットフィールド

要旨

(明示的もしくは暗黙的な)符号付き整数型のビットフィールドの幅が 1ビットで定義されています。

プロパティ

クラス名 Bit-field Too Short
日本語クラス名 短すぎるビットフィールド
クラス分類 スタイル (style)
ニーモニック LANG.TYPE.BFSHORT
カテゴリー
MisraC2023 MisraC2023:6.2 Single-bit named bit fields shall not be of a signed type
Misra2012 Misra2012:6.2 Single-bit named bit fields shall not be of a signed type
Misra2004 Misra2004:6.5 Bit fields of signed type shall be at least 2 bits long
AUTOSARC++14 AUTOSARC++14:M9-6-4 Named bit-fields with signed integer type shall have a length of more than one bit.
MisraC++2008 MisraC++2008:9-6-4 Named bit-fields with signed integer type shall have a length of more than one bit.
MisraC++2023 MisraC++2023:12.2.1 Bit fields should not be declared
  MisraC++2023:12.2.3 A named bit-field with signed integer type shall not have a length of one bit
対応言語 C および C++ で利用可能です。
有効/無効設定 このワーニングクラスのチェックはデフォルトで無効になっており、プロジェクトには非正規の C向けAST が必要になります。有効にするにはプロジェクト設定ファイル (configuration file) に以下の WARNING_FILTER ルールと RETAIN_UNNORMALIZED_C_AST 設定を追加してください。
RETAIN_UNNORMALIZED_C_AST = Yes
WARNING_FILTER += allow class="Bit-field Too Short"
注:非正規化された AST を継続して使用した場合、使用ディスク容量が増加し解析時間が長くなる可能性があります。

typedef int plainint;
typedef signed int signedint;
typedef unsigned int uint;

struct widthstruct{
  signed int si1      : 2;
  signed int si2      : 1; /* 'Bit-field Too Short' warning issued here */
  signedint si3       : 1; /* 'Bit-field Too Short' warning issued here */
  unsigned int si4    : 1;
  uint si5            : 1;
  int si6             : 1; /* 'Bit-field Too Short' warning issued here */
  plainint si7        : 1; /* 'Bit-field Too Short' warning issued here */
};

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

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