2023-05-03 11:06:20 +02:00
== Why is this an issue?
2021-06-08 14:23:48 +02:00
The values which may be represented by a bit-field of length one may not meet developer expectations. Anonymous signed bit-fields of any length are allowed.
2023-05-03 11:06:20 +02:00
=== Noncompliant code example
2021-06-08 14:23:48 +02:00
2022-02-04 17:28:24 +01:00
[source,cpp]
2021-06-08 14:23:48 +02:00
----
struct S
{
signed int a : 1; // Noncompliant, signed fields require at least two bits
signed int : 1; // Compliant, cannot be referenced
signed int : 0; // Compliant, cannot be referenced
};
----
2023-05-03 11:06:20 +02:00
=== Compliant solution
2021-06-08 14:23:48 +02:00
2022-02-04 17:28:24 +01:00
[source,cpp]
2021-06-08 14:23:48 +02:00
----
struct S
{
signed int a : 2; // Compliant
signed int : 1; // Compliant, cannot be referenced
signed int : 0; // Compliant, cannot be referenced
};
----
2023-05-03 11:06:20 +02:00
== Resources
2021-06-08 14:23:48 +02:00
* MISRA {cpp}:2008, 9-6-4
ifdef::env-github,rspecator-view[]
2021-06-08 15:52:13 +02:00
'''
2021-06-08 14:23:48 +02:00
== Comments And Links
(visible only on this page)
2023-05-25 14:18:12 +02:00
=== duplicates: S2216
2021-06-08 14:23:48 +02:00
endif::env-github,rspecator-view[]