STRUCT-signed-bit
Synopsis
There are signed single-bit fields (excluding anonymous fields).
Enabled by default
No
Severity/Certainty
Low/Low

Full description
There are signed single-bit fields (excluding anonymous fields). A signed bitfield should have size at least two, because one bit is required for the sign. This check is identical to MISRAC2004-6.5, MISRAC++2008-9-6-4, MISRAC2012-Rule-6.2, MISRAC++2023-12.2.3.
Coding standards
- MISRA C:2004 6.5
(Required) Bitfields of signed type shall be at least 2 bits long.
- 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;
};