AUTOSAR C++14 Rule A15-5-2
Program shall not be abruptly terminated. In particular, an implicit or explicit invocation of std::abort(), std::quick_exit(), std::_Exit(), std::terminate() shall not be done
Since R2021b
Description
Rule Definition
Program shall not be abruptly terminated. In particular, an implicit or explicit invocation of std::abort(), std::quick_exit(), std::_Exit(), std::terminate() shall not be done.
Rationale
Functions such as std::abort()
, std::quick_exit()
,
and std::_Exit()
terminate the program immediately without invoking any
exit handlers or calling any destructors for the constructed objects. The
std::terminate()
function implicitly calls
std::abort()
to terminate the program abruptly. Exceptions that are
unhandled or cannot be handled might also cause abrupt termination of the program.
Depending on your environment, the compiler might not release the allocated resources and unwind the stack when the program is terminated abruptly, leading to issues such as memory leaks. Such abnormal program terminations might make the code vulnerable to denial-of-service attacks. Avoid terminating the program abruptly.
Polyspace Implementation
Polyspace® flags the operations that might result in abrupt termination of the program. For instance:
The destructor of a class exits with an unhandled exception. See
AUTOSAR C++14 Rule A15-5-3
.The constructor of a global or a static object is invoked directly but it is not explicitly specified as
noexcept
. SeeAUTOSAR C++14 Rule A15-2-1
.A
noexcept
function raises an unhandled exception. SeeAUTOSAR C++14 Rule A15-4-2
.The argument of a
throw
statement raises an exception. SeeAUTOSAR C++14 Rule M15-1-1
.Unsafe termination functions such as
std::_Exit
,std::abort
, andstd::quick_exit
are explicitly invoked.The function
std::terminate
is explicitly invoked.A handler for abnormal termination is explicitly registered by using the functions
std::set_terminate
orstd::get_terminate
.A handler for normal termination that is registered to
std::atexit
raises an unhandled exception.
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: Exception handling |
Category: Required, Partially automated |