PC-lint on switch case labels: Violates MISRA C++ 2008 Required Rule 5-0-12

Solution 1:

Try using an enum, as they are "known", using the following code for example, the second function does not have the issue.

#include <cstdint>

namespace testa
{
    static const uint8_t FirstData = 1;
    static const uint8_t SecondData = 2;

    int32_t func_A(uint8_t Numdata)
    {
        int32_t ret = 0;
        switch (Numdata)   //Numdata is either FirstData, SecondData
        {
        case FirstData:
            ret = 1;
        case SecondData:
            ret = 2;
        }

        return ret;
    }
}

namespace testb
{
    enum data {
        FirstData,
        SecondData
    };

    int32_t func_B(data Numdata)
    {
        int32_t ret = 0;
        switch (Numdata)   //Numdata is either FirstData, SecondData
        {
        case FirstData:
            ret = 1;
        case SecondData:
            ret = 2;
        }

        return ret;
    }
}

int32_t main(int32_t, int8_t*[])
{
    int32_t z = 0;
    z += testa::func_A(testa::FirstData);
    z += testa::func_A(testa::SecondData);
    z += testb::func_B(testb::FirstData);
    z += testb::func_B(testb::SecondData);

    return z;
}

Solution 2:

The rule says : "[Explicitly] signed char and unsigned char type shall only be used for the storage and use of numeric values." I assume this disallows use as labels, and the lint error message is badly worded. I see nothing wrong with it and would just disable the warning for that code, or, if necessary, for the whole file.