A7-2-1 Still relevant in C++14? - Printable Version +- MISRA Discussion Forums (https://forum.misra.org.uk) +-- Forum: MISRA C++ (https://forum.misra.org.uk/forumdisplay.php?fid=18) +--- Forum: AUTOSAR C++:2014 rules (https://forum.misra.org.uk/forumdisplay.php?fid=185) +--- Thread: A7-2-1 Still relevant in C++14? (/showthread.php?tid=1724) |
A7-2-1 Still relevant in C++14? - cgpzs - 29-01-2025 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? RE: A7-2-1 Still relevant in C++14? - misra cpp - 31-01-2025 (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. 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. |