Main Content

MISRA C:2023 Rule 2.4

A project should not contain unused tag declarations

Since R2024a

Description

This checker is deactivated in a default Polyspace® as You Code analysis. See Checkers Deactivated in Polyspace as You Code Analysis (Polyspace Access).

Rule Definition

A project should not contain unused tag declarations.

Rationale

If a tag is declared but not used, a reviewer does not know if the tag is redundant or if it is unused by mistake.

Troubleshooting

If you expect a rule violation but do not see it, refer to Diagnose Why Coding Standard Violations Do Not Appear as Expected.

Examples

expand all

void unusedTag ( void )
{
    enum state1 { S_init, S_run, S_sleep };	/* Non-compliant  */			
}

void usedTag ( void )
{
    enum state2 { S_init, S_run, S_sleep };	/* Compliant  */			
    enum state2 my_State = S_init;
}

In this example, in the function unusedTag, the tag state1 is defined but not used. Therefore, the rule is violated.

typedef struct record_t		/* Non-compliant  */	
{
    unsigned short key;
    unsigned short val;
} record1_t;


typedef struct			   /* Compliant */						
{
    unsigned short key;
    unsigned short val;
} record2_t;

record1_t myRecord1_t;
record2_t myRecord2_t;

In this example, the tag record_t appears only in the typedef of record1_t. In the rest of the translation unit, the type record1_t is used. Therefore, the rule is violated.

Check Information

Group: Unused Code
Category: Advisory
AGC Category: Readability

Version History

Introduced in R2024a