V2660. MISRA. A function declared with a _Noreturn specifier should not return to its caller.
This diagnostic rule is based on the MISRA (Motor Industry Software Reliability Association) software development guidelines.
This diagnostic rule is relevant only for C.
The _Noreturn
specifier prompts the compiler that the function does not return control flow to the caller on any execution path. A violation of this contract leads to undefined behavior (C11, section 6.7.4.8, Annex J2).
Here is an example of erroneous code:
_Noreturn void foo(int x)
{
if (x != 0)
abort();
}
In this example, when the value of the x
parameter is zero, foo
returns control flow to the caller function. This contradicts the _Noreturn
specifier.
The fixed code:
_Noreturn void foo(int x)
{
abort();
}