MISRAC++2023-12.2.2 (C++ only)
In this section:
Synopsis
(Required) A bit-field shall have an appropriate type
Enabled by default
Yes
Severity/Certainty
Medium/High

Full description
Types with implementation defined sign like char or enums without underlying type shall not be used for bit-fields to avoid implementation defined behavior.
Coding standards
This check does not correspond to any coding standard rules.
Code examples
The following code example fails the check and will give a warning:
struct example
{
char a : 2; // Non-compliant
char b : 2; // Non-compliant
};
The following code example passes the check and will not give a warning about this issue:
#include <cstdint>
struct example
{
std::uint8_t a : 2; // Compliant
std::uint8_t b : 2; // Compliant
};