Search code examples
cmacrosmisra

Unpermitted operand to operator '|' [MISRA 2012 Rule 10.1, required]


Observed below Misra warning for 10.1 rule. It says "Unpermitted operand to operator ‍‍‍|.

How to avoid this warning ?

This is misleading as | is not being used in the statement.

#define C_BYTE unsigned char
C_BYTE SendStatus;
#define SEND_PENDING   0x10

SendStatus &= (C_BYTE) ~ ((C_BYTE) SEND_PENDING);

EDIT:

I am using Misra 2012 to check QA-C warnings. compiling the code using a batch file.

#define BYTE unsigned char
#define REQUEST  0x01
#define PENDING  0x10
#define D_PENDING  0x20
#define SEND_PENDING (PENDING|D_PENDING|REQUEST)

struct cp {    
  BYTE SessionStatus;
  BYTE SendStatus;
};

Case 1:

BYTE fun2( void )
{
    cp.SendStatus &= (BYTE) ~ ((BYTE) SEND_PENDING); //Warning observed for this line

    if((cp.SendStatus & (BYTE) REQUEST) != 0u)
    {
        cp.SendStatus &= (BYTE) ~ (BYTE) REQUEST;
        return 1;
    }
}

Case 2:

void fun1(void)
{
    BYTE ChkStatus = (cp.SendStatus & (BYTE) SEND_PENDING); //Warning observed for this line

    if ((bool)ChkStatus)
    {
        cp.SendStatus |= ((BYTE) REQUEST);
    }
    else
    {
        cp.SendStatus |= ((BYTE) PENDING);
    }

}

Solution

  • Modify as below to avoid this warning.

    #define REQUEST    0x01u
    #define PENDING    0x10u
    #define D_PENDING  0x20u