18-09-2026, 01:01 PM
The short answer is that as far as M5-0-4 is concerned, all aspects of your switch statement are compliant.
The M in M5-0-4 means that this Autosar rule is taken directly from MISRA C++:2008 "An implicit integer conversion shall not change the signedness of the underlying type". "underlying type" is in italics, meaning its using the MISRA definition of the term, NOT the C++ language definition. Under the MISRA definition, an enum is not an integer type, its underlying type is itself (Foo). So the switch statement is performing comparisons between x (of underlying type Foo) and enum values (FOO_A etc.) also of underlying type Foo - there are therefore no conversions, so the rule does not apply.
This MISRA definition of "underlying type" proved both confusing and unpopular and has been removed from subsequent versions of both MISRA C and C++.
We've looked at the equivalent rule in MISRA:2023. Again, your specific example would be compliant, but if the example is changed so the unscoped enum has an underlying type (as per the C++ language definition), then the code may be non-compliant (depending upon the signedness). This wasn't the intension, so has been added as an issue to be addressed.
The M in M5-0-4 means that this Autosar rule is taken directly from MISRA C++:2008 "An implicit integer conversion shall not change the signedness of the underlying type". "underlying type" is in italics, meaning its using the MISRA definition of the term, NOT the C++ language definition. Under the MISRA definition, an enum is not an integer type, its underlying type is itself (Foo). So the switch statement is performing comparisons between x (of underlying type Foo) and enum values (FOO_A etc.) also of underlying type Foo - there are therefore no conversions, so the rule does not apply.
This MISRA definition of "underlying type" proved both confusing and unpopular and has been removed from subsequent versions of both MISRA C and C++.
We've looked at the equivalent rule in MISRA:2023. Again, your specific example would be compliant, but if the example is changed so the unscoped enum has an underlying type (as per the C++ language definition), then the code may be non-compliant (depending upon the signedness). This wasn't the intension, so has been added as an issue to be addressed.
Posted by and on behalf of
the MISRA C++ Working Group
the MISRA C++ Working Group

