Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
unused enum constant
#1
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?
#2
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



  •     Anonymous enum type: This does not have a tag and is not used to define any object.
               Enum constants have an essential type which is the smallest type of the same sign that can hold the constant.


  •  Named enum type: This either has a tag, typedef or is directly used to name a constant.
              Enum constants have an essential type of the associated enum type.

 




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 };
enum tag { ENUM_A = 1, ENUM_B = 2, ENUM_C = 3 };

uint8_t u8 = ENUM_A;  // assignment of essentially enum to essentially unsigned char 
                      // violates rule 10.3   
       
uint8_t u8 = A;       // assignment of essentially signed char to essentially unsigned char
                      // permitted by rule 10.3 exception 1
     
     Comparison with uint8_t will violation rules 10.4 in both cases




Code:
     u8 > ENUM_A  // Balance essentially unsigned char with essentially enum type
                  // violates rule 10.4
       
      u8 > A      // Balance essentially unsigned char with essentially signed char type
                  // violates rule 10.4
Posted by and on behalf of the MISRA C Working Group


Forum Jump:


Users browsing this thread: 2 Guest(s)