Search code examples
c++charklocwork

klocwork CWARN.SIGNEDBIT on unsigned char


I have C++ code which contains:

struct Struct
{
    uint8_t varA : 1;
    uint8_t varB : 1;
    uint8_t varC : 1;
};

When I am running Klocwork 10 on it, I get a warning:

CWARN.SIGNEDBIT (4:Review) Analyze
Bit field 'varA' has one bit and is signed

And same for other variables in this struct. uint8_t is unsigned char typedef. When i am trying to use signed char then I get an error, not a warning like here. Using unsigned int solves problem but i want to use char instead.

My question here is: why this warning appears and how to solve it?


Solution

  • Looks like it is a Klocwork 10 bug, I will add this as an exception to the test output. Thanks for reply