Posts: 54
Threads: 27
Joined: Mar 2021
Reputation:
1
Rule A7-2-1 seems copied verbatim from the MISRA C++ 2008 rules. However, there's a key difference: C++14 has scoped enums. There, it is not unspecified (nor undefined) to cast an integer to the enum type when it is not any of the enumerators, since the valid range for the enum is the range of the underlying type.
Based on that, what would be the rationale for keeping A7-2-1 in the AUTOSAR C++14 rules?
Posts: 260
Threads: 1
Joined: Jun 2008
Reputation:
6
(29-01-2025, 10:03 AM)cgpzs Wrote: Rule A7-2-1 seems copied verbatim from the MISRA C++ 2008 rules. However, there's a key difference: C++14 has scoped enums. There, it is not unspecified (nor undefined) to cast an integer to the enum type when it is not any of the enumerators, since the valid range for the enum is the range of the underlying type.
Based on that, what would be the rationale for keeping A7-2-1 in the AUTOSAR C++14 rules?
Whilst you are right that when you have a base-type the behaviour is well defined, A7-2-1 also applies when there is no base-type.
Addition, the second paragraph of the rationale applies to all enums, even those that have a base-type.
For a more modern interpretation see MISRA C++:2023.
Posted by and on behalf of
the MISRA C++ Working Group