C and C++


LANG.TYPE.BFSIGN : Bit-field Signedness Not Explicit

Summary

A bit-field type is neither explicitly signed nor explicitly unsigned.

C99 bit-fields with _Bool type will not trigger warnings of this class.

Properties

Class Name Bit-field Signedness Not Explicit
Significance style
Mnemonic LANG.TYPE.BFSIGN
Categories
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.1 Bit fields should not be declared
CERT-C CERT-C:INT12-C Do not make assumptions about the type of a plain int bit-field when used in an expression
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 Signedness Not Explicit"
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

struct mystruct{
    int A               : 2; /* 'Bit-field Signedness Not Explicit' warning issued here */ 
    signed int B        : 2;                      /* explicitly signed */ 
    unsigned int C      : 2;                      /* explicitly unsigned */ 
};

typedef int plainint;
typedef signed int signedint;

struct myotherstruct{
    plainint D          : 2; /* 'Bit-field Signedness Not Explicit' warning issued here */ 
    signedint E         : 2;                      /* explicitly signed (in typedef) */ 
};

Relevant Configuration File Parameters

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