Why is this an issue?
This is a draft version of a MISRA C++ 202x rule proposed for public review.
MISRA Rule 6.6.4
Analysis Type: Undecidable,System
Leaving a function as the result of an exception is not a return.
A function’s compliance with this rule is determined independently of the context in which the function is called. For example, a boolean parameter
is treated as if it may have a value of
false, even if all the calls expressed in the current program use a value of
Returning from a function declared as
[[noreturn]] results in undefined behaviour.
Note: a function may be declared as
- It only exits by throwing an exception; or
- It loops endlessly; or
- It causes program termination.
[[noreturn]] void kill_the_process() // Compliant
std::abort(); // Note - std::abort() is also [[noreturn]]
[[noreturn]] void throw_some() // Compliant - only exits with an exception
[[noreturn]] void g( bool b ) // Non-compliant - returns if 'b' is false
if ( b )
Copyright The MISRA Consortium Limited © 2023
- S5267 targets the same defect as this rule but for a non-mission-critical context.
- MISRA C++ 2023 Rule 3.2.2 - All declarations of a variable or function shall have the same type