cmisrapc-lint

global macro 'INVALIDATION_ADDR' of type 'void' not referenced [MISRA 2012 Rule 2.5, advisory]


I observed the above warning when I define MACRO but not used anywhere in code. But at some instance, I am getting this warning for the MACRO which is being used in code as well.

I have defined macro - INVALIDATION_ADDR and used at some places as well. However, I observed the same MISRA warning. I am not sure regarding the reason to get this warning. How to avoid this warning.

Case 1:

global macro 'INVALIDATION_ADDR' of type 'void' not referenced [MISRA 2012 Rule 2.5, advisory]

lint rule 755

global macro 'Symbol' (Location) not referenced -- A 'global' macro is one defined in a header file. This message is given for macros defined in non-library headers. The macro is not used in any of the modules comprising the program. This message is suppressed for unit checkout (-u option).

typedef uint32 AddressType;

#define INVALIDATION_ADDRESS   (AddressType)0x12345678U

void fun1()
{
     AddressType Address;
     Address = INVALIDATION_ADDRESS;
}

Case 2:

global typedef 'ConditionsEnumType' of type 'ConditionsEnumType' (line 110, file ITypes.h) not referenced [MISRA 2012 Rule 2.3, advisory]

lint rule 756

global typedef 'Symbol' (Location) not referenced -- This message is given for a typedef symbol declared in a non-library header file. The symbol is not used in any of the modules comprising a program. This message is suppressed for unit checkout (-u option).

typedef unsigned char       uint8; 
typedef uint8 StateType;

typedef enum
    {
        BLOCK      =  0x80U,
        HEADER     =  0x81U,
        DATA       =  0x82U,    
        OUTCOME    =  0x84U
    } ConditionsEnumType;

/* used in below func */ 
    void fun2()
    {
         StateType state;
         state = (StateType) BLOCK; 
    }

Solution

  • Case 1:

    This diagnostic:

    global macro 'INVALIDATION_ADDR' of type 'void' not referenced [MISRA 2012 Rule 2.5, advisory]
    

    does not match this macro:

    #define INVALIDATION_ADDRESS   (AddressType)0x12345678U
    

    So I think the MISRA checker is right because you have another macro definition that is not referenced.

    Case 2:

    The typedef of ConditionsEnumType is in fact not referenced if you don't define any variable with this type.

    You might like to change your source into:

    void fun2()
    {
         ConditionsEnumType state;
         state = BLOCK; 
    }