AUTOSAR C++14 Rule A7-6-1
Description
Rule Definition
Functions declared with the [[noreturn]] attribute shall not return.
Rationale
If you declare a function by using the [[noreturn]]
attribute, the
compiler expects that the function does not return the flow of execution. That is, if a
[[noreturn]]
function f()
is called from
main()
, then the compiler expects that the flow of execution is not
returned to main()
. If such a function eventually returns the flow of
execution, it leads to undefined behavior, which can be exploited to cause data integrity
violations.
If a function has no return
statement, then the final closing brace
of a function implies an implicit return
. Omitting a
return
statement in the function does not prevent the flow of execution
from returning. A [[noreturn]]
function can prohibit returning the flow
of execution to the calling function by:
Entering an infinite loop
Raising an exception
Calling another
[[noreturn]]
function
Polyspace Implementation
If a function specified as [[noreturn]]
returns the control flow to
its caller, Polyspace® flags the [[noreturn]]
function.
Troubleshooting
If you expect a rule violation but Polyspace does not report it, see Diagnose Why Coding Standard Violations Do Not Appear as Expected.
Examples
Check Information
Group: Declaration |
Category: Required, Automated |
Version History
Introduced in R2020b