11.1.6 MISRA2004 check (rule number 10.1)

Unnecessary message may be output for statements with enumerated-type variables, return statements with
enumerated-type return values, or statements with enumerators in a file satisfying the following conditions (1), (2), and (3).

(1)

Option -signed_char is not specified and enumerated-type definitions whose range of enumerator value is within a range of 0 to 255 are included,
or
option -signed_char is specified and enumerated-type definitions whose range of enumerator value is within a range of -128 to 255 are included.

(2)

Statements with enumerated-type variables, return statements with enumerated-type return values, or statements with enumerators are included.

(3)

MISRA check option against rule 10.1 is specified.

Example

typedef enum E { E1 = 0, E2, E3 } etype;
etype func( void );
etype evar;
etype func(void)
{
        evar = E1;                      // Message against rule 10.1 is output.
        return E1;                      // Message against rule 10.1 is output.
}

 

(Workaround)

Cast enumerators to enumerated type.

typedef enum E { E1 = 0, E2, E3 } etype;
etype func( void );
etype evar;
etype func(void)
{
        evar = (etype)E1;               // Cast enumerator E1 to etype
        return (etype)E1;               // Cast enumerator E1 to etype
}