Skip to main content

IAR Embedded Workbench for RX 5.20

MISRAC++2023-10.2.3 (C++ only)

In this section:
Synopsis

(Required) The numeric value of an unscoped enumeration with no fixed underlying type shall not be used

Enabled by default

Yes

Severity/Certainty

Low/Medium

lowmedium.png
Full description

When the underlying type is not specified, the type is implementation defined which can lead to unexpected conversions.

Coding standards

This check does not correspond to any coding standard rules.

Code examples

The following code example fails the check and will give a warning:

enum E { e1a = 100, e1b = 200 };

void example( E e ) {
  const auto n = e + 1;      // Non-compliant - addition
}

The following code example passes the check and will not give a warning about this issue:

enum E : int { e1a = 100, e1b = 200 };

void example( E e ) {
  const auto n =  e + 1;  // Compliant
}