![]() |
9.4.2 assert(false) in default clause, compliant? - Printable Version +- MISRA Discussion Forums (https://forum.misra.org.uk) +-- Forum: MISRA C++ (https://forum.misra.org.uk/forumdisplay.php?fid=18) +--- Forum: MISRA C++:2023 guidelines (https://forum.misra.org.uk/forumdisplay.php?fid=188) +---- Forum: 4.9 Statements (https://forum.misra.org.uk/forumdisplay.php?fid=195) +---- Thread: 9.4.2 assert(false) in default clause, compliant? (/showthread.php?tid=1740) |
9.4.2 assert(false) in default clause, compliant? - cgpzs - 03-06-2025 Hi, MISRA C++:2023 Rule 9.4.2 provides a number of requirements on switch statements, in particular that every branch shall be unconditionally terminated. Assuming that assertions are always enabled (also in Release builds), would this code be compliant with 9.4.2? Code: enum class Foo assert(false) leads to calling the assert_handler function, which is marked [[noreturn]], so it would fall under requirement 5f of the rule. Would you agree? Thanks! RE: 9.4.2 assert(false) in default clause, compliant? - misra cpp - 06-06-2025 If asserts are enabled, we'd say yes, using assert as the default behaviour would be acceptable However, in general, a static analyser cannot determine if asserts are enabled or not. Your example may still be acceptable, as the compiler may warn that not all paths return a value, but in general this is not likely to be the case. |