C and C++


LANG.TYPE.BFSHORT : Bit-field Too Short

Summary

A bit-field has (explicitly or implicitly) signed type and width 1.

Properties

Class Name Bit-field Too Short
Significance style
Mnemonic LANG.TYPE.BFSHORT
Categories
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
Availability Available for C and C++.
Enabling Checks for this warning class are disabled by default, and require the unnormalized C ASTs for the project. To enable them, add the following WARNING_FILTER rule and RETAIN_UNNORMALIZED_C_AST specification to the project configuration file.
RETAIN_UNNORMALIZED_C_AST = Yes
WARNING_FILTER += allow class="Bit-field Too Short"
Note that retaining the unnormalized ASTs will increase the disk space used to store the project representation, and may make the analysis take longer.

Example

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 */
};

Relevant Configuration File Parameters

The following configuration file parameters affect checks for this warning class.