This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MISRA 12.8 and MISRA 10.5 False Positives?



Hello

I was wondering if the compiler's MISRA checking is reporting false positives. I have the following code

#define DEF_X (0x00000001UL)
#define DEF_Y (4U)

static void foo(void)

{

    uint32 nReadData;

    nReadData = DEF_X << DEF_Y;

}

This gives me a MISRA error...

#1397-D (MISRA-C:2004 10.5/R) If the bitwise operators ~ and << are applied to an operand of underlying type unsigned char or unsigned short, the result shall be immediately cast to the underlying type of the operand.

But the underlying type is a "UL" or 32bit unsigned integer.

If I try to fix the error using the code...

 nReadData = (uint32)DEF_X << DEF_Y;

This gives me a MISRA error...

#1407-D (MISRA-C:2004 12.8/R) The right-hand operand of a shift operator shall lie between zero and one less than the width in bits of the underlying type of the left-hand operand

But the right hand operator has a value of 4 and the left hand operator is 32 bits.

The only way I can solve the problem is by assigning the #define values to temporary variables and then doing the shift operation with these.

With this in mind I think the misra checking is not handling the #define values correctly.. Am I correct in this assumption?