V2521. MISRA. Only the first member of enumerator list should be explicitly initialized, unless all members are explicitly initialized.

This diagnostic rule is based on the software development guidelines developed by MISRA (Motor Industry Software Reliability Association).

This diagnostic rule is relevant only to C++ programs.

The analyzer has detected an enumeration whose members are initialized in a mixed way (explicitly and implicitly). This may result in duplicating their values.

Here is an example of incorrect code:

enum Suits 

The way the elements are initialized here results in assigning the same value to the members 'SUITS_HEARTS' and 'SUITS_UNKNOWN'. It is not clear if this was done on purpose or by mistake.

The warning is not issued in the following cases:

  • only the first enumeration element is initialized explicitly;
  • all enumeration elements are initialized implicitly;
  • all enumeration elements are initialized explicitly.

This diagnostic is classified as:

  • MISRA-CPP-8.5.3

Bugs Found

Checked Projects
Collected Errors
14 526
This website uses cookies and other technology to provide you a more personalized experience. By continuing the view of our web-pages you accept the terms of using these files. If you don't want your personal data to be processed, please, leave this site. Learn More →