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?
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!
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
{
a,
b
};
int get(Foo f)
{
switch(f)
{
case Foo::a: { return 123; }
case Foo::b: { return 321; }
default: { assert(false && "Unreachable"); }
}
}
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!