MISRAC2004-6.5
In this section:
Synopsis
(Required) Bitfields of signed type shall be at least 2 bits long.
Enabled by default
Yes
Severity/Certainty
Low/Low

Full description
Signed bitfields consisting of a single bit (excluding anonymous fields) were found. This check is identical to STRUCT-signed-bit, MISRAC++2008-9-6-4, MISRAC2012-Rule-6.2, MISRAC++2023-12.2.3.
Coding standards
- MISRA C:2012 Rule-6.2
(Required) Single-bit named bit fields shall not be of a signed type
- MISRA C++ 2008 9-6-4
(Required) Named bit-fields with signed integer type shall have a length of more than one bit.
- MISRA C++ 2023 12.2.3
(Required) A named bit-field with signed integer type shall not have a length of one bit
Code examples
The following code example fails the check and will give a warning:
struct S
{
signed int a : 1; // Non-compliant
};
The following code example passes the check and will not give a warning about this issue:
struct S
{
signed int b : 2;
signed int : 0;
signed int : 1;
signed int : 2;
};