1

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; 
    }
kapilddit
  • 1,729
  • 4
  • 26
  • 51
  • 2
    Would you mind to show us the **real** source (of a [example]) not the one made up for this question, please? Evidences: In case 1 the diagnostic talks about `INVALIDATION_ADDR` but your source uses `INVALIDATION_ADDRESS`. This might be the error, though. The source of case 2 can't be compiled due to the spelling error `unsinged`. Anyway, in case 2 you declare the variable `state` as `unsigned char` and not as `ConditionsEnumType` so the MISRA checker is right. – the busybee Sep 13 '19 at 05:55
  • Now I checked, all MACRO belongs to the same source (.h) file. Checking if that file is included in compilation or not. – kapilddit Sep 13 '19 at 05:57
  • @thebusybee corrected the spelling error. – kapilddit Sep 13 '19 at 06:11

1 Answers1

4

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; 
}
the busybee
  • 10,755
  • 3
  • 13
  • 30