unused enum constant - Printable Version +- MISRA Discussion Forums (https://forum.misra.org.uk) +-- Forum: MISRA C (https://forum.misra.org.uk/forumdisplay.php?fid=4) +--- Forum: MISRA C:2012 and MISRA C:2023 guidelines (https://forum.misra.org.uk/forumdisplay.php?fid=21) +---- Forum: 7.1 The implementation (https://forum.misra.org.uk/forumdisplay.php?fid=178) +---- Thread: unused enum constant (/showthread.php?tid=1602) |
unused enum constant - kprzygoda - 10-03-2022 I have created enum constant and using it only for assigment to uint8_t or if comparison of uint8_t to this constant, coverity from synopsys configured for MISRA C 2012 is generating rule violation: Type has tag xxxx_enum but that tag is never used. Is there any clear way of get rid of this message? RE: unused enum constant - misra-c - 23-04-2022 The message "Type has tag xxxx_enum but that tag is never used" would indicate a violation of rule 2.4 which implies that you are using the enumeration constants but are never declaring an object with that type. MISRA C:2012 divides enumeration constants into two types as described in Appendix D.5. They can be summarised as follows
It looks as if you are trying to use an enum constant as an "Anonymous enum type", but have included the tag. Assignments to uint8_t are only possible for assignments of anonymous enum types. For example: Code: enum { A = 1, B = 2, C = 3 }; Comparison with uint8_t will violation rules 10.4 in both cases Code: u8 > ENUM_A // Balance essentially unsigned char with essentially enum type |