JavaScript is not currently enabled, but is required for full CodeSonar manual search and browse functionality.

If you are viewing this file in your hub's Web GUI, enable JavaScript in your browser: you will also need it for GUI functionality.

If you opened this file directly from disk, your browser may be directly suppressing JavaScript functionality: certain browsers perform this suppression on local files (but not files delivered by web servers) for security reasons.

CodeSonar® 9.2p0 CONFIDENTIAL CodeSecure Inc
C and C++


LANG.STRUCT.INIT.ENUM : Inconsistent Enumerator Initialization

Summary

The elements in an enumeration have been initialized in a way that conflicts with the JPL rule 12 requirement that enumeration declarations initialize either:

Properties

Class Name Inconsistent Enumerator Initialization
Significance style
Mnemonic LANG.STRUCT.INIT.ENUM
Categories
MisraC2025 MisraC2025:8.12 Within an enumerator list, the value of an implicitly-specified enumeration constant shall be unique
MisraC2023 MisraC2023:8.12 Within an enumerator list, the value of an implicitly-specified enumeration constant shall be unique
Misra2012 Misra2012:8.12 Within an enumerator list, the value of an implicitly-specified enumeration constant shall be unique
Misra2004 Misra2004:9.3 In an enumerator list, the "=" construct shall not be used to explicitly initialise members other than the first, unless all items are explicitly initialised
AUTOSARC++14 AUTOSARC++14:A7-2-4 In an enumeration, either (1) none, (2) the first or (3) all enumerators shall be initialized.
MisraC++2008 MisraC++2008:8-5-3 In an enumerator list, the = construct shall not be used to explicitly initialize members other than the first, unless all items are explicitly initialized.
MisraC++2023 MisraC++2023:11.6.3 Within an enumerator list, the value of an implicitly-specified enumeration constant shall be unique
CWE CWE:665 Improper Initialization
  CWE:710 Improper Adherence to Coding Standards
CERT-C CERT-C:INT09-C Ensure enumeration constants map to unique values
JSF++ JSF++:145 In an enumerator list, the '=' construct shall not be used to explicitly initialize members other than the first, unless all items are explicitly initialized.
JPL JPL:12 Do not use selective value assignments to elements of an enum list.
Availability Available for C and C++.
Enabling Checks for this warning class are disabled by default, and require the unnormalized C ASTs for the project. To enable them, add the following WARNING_FILTER rule and RETAIN_UNNORMALIZED_C_AST specification to the project configuration file.
RETAIN_UNNORMALIZED_C_AST = Yes
WARNING_FILTER += allow class="Inconsistent Enumerator Initialization"
Note that retaining the unnormalized ASTs will increase the disk space used to store the project representation, and may make the analysis take longer.

Example

enum no_second_init { /* 'Inconsistent Enumerator Initialization' warning issued here */
   NO_SECOND_INIT1 = 0,
   NO_SECOND_INIT2, 
   NO_SECOND_INIT3 = 2
};

Relevant Configuration File Parameters

The following configuration file parameters affect checks for this warning class.

 

To report problems with this documentation, please visit https://support.codesecure.com/.