C and C++


LANG.TYPE.BFINT : 不適切なビットフィールド型

要旨

ビットフィールドが intsigned intunsigned int、(C99のみ) _Bool の潜在型ではありません。

プロパティ

クラス名 Inappropriate Bit-field Type
日本語クラス名 不適切なビットフィールド型
クラス分類 スタイル (style)
ニーモニック LANG.TYPE.BFINT
カテゴリー
MisraC2023 MisraC2023:6.1 Bit-fields shall only be declared with an appropriate type
Misra2012 Misra2012:6.1 Bit-fields shall only be declared with an appropriate type
Misra2004 Misra2004:6.4 Bit fields shall only be defined to be of type unsigned int or signed int
MisraC++2008 MisraC++2008:9-6-2 Bit-fields shall be either bool type or an explicitly unsigned or signed integral type.
  MisraC++2008:9-6-3 Bit-fields shall not have enum type.
MisraC++2023 MisraC++2023:12.2.2 A bit-field shall have an appropriate type
JSF++ JSF++:154 Bit-fields shall have explicitly unsigned integral or enumeration types only.
対応言語 C および C++ で利用可能です。
有効/無効設定 このワーニングクラスのチェックはデフォルトで無効になっており、プロジェクトには非正規の C向けAST が必要になります。有効にするにはプロジェクト設定ファイル (configuration file) に以下の WARNING_FILTER ルールと RETAIN_UNNORMALIZED_C_AST 設定を追加してください。
RETAIN_UNNORMALIZED_C_AST = Yes
WARNING_FILTER += allow class="Inappropriate Bit-field Type"
注:非正規化された AST を継続して使用した場合、使用ディスク容量が増加し解析時間が長くなる可能性があります。

typedef int plainint;
typedef short int shortint;

struct mystruct{
    char C             : 2;   /* 'Inappropriate Bit-field Type' warning issued here */
    plainint D         : 2;                       /* underlyingly int */
    shortint E         : 2;   /* 'Inappropriate Bit-field Type' warning issued here */
    long F             : 2;   /* 'Inappropriate Bit-field Type' warning issued here */ 
    _Bool G            : 1;                       /* _Bool permitted in C99 */
};

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

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