If a function is declared to be noexcept, noexcept(true) or noexcept(<true condition>), then it shall not exit with an exception
If a function is declared to be noexcept, noexcept(true) or noexcept(<true condition>), then it shall not exit with an exception.
You can specify that a callable entity does not raise an exception by specifying it as
noexcept, or noexcept(true), or
noexcept(<true condition>). The compiler expects that a
noexcept function does not exit with an exception. Based on this
assumption, the compiler omits the exception handing process for noexcept
functions. When a noexcept function exits with an exception, the
exception becomes unhandled.
If a noexcept function exits with an exception, the compiler invokes
std::terminate() implicitly. The function
std::terminate() terminates the program execution in an
implementation-defined manner. That is, the exact process of program termination depends on
the particular set of software and hardware that you use. For instance,
std:terminate() might invoke std::abort() to
abnormally abort the execution without unwinding the stack, leading to resource leak and
security vulnerabilities.
Specify functions as noexcept or noexcept(true)
only when you know the functions raise no exceptions. If you cannot determine the exception
specification of a function, specify it by using noexcept(false).
If you specify a callable entity by using noexcept,
noexcept(true), or noexcept(<true condition>),
Polyspace® checks the callable entity for unhandled exceptions and flags the callable
entity if it might exit with an exception.
When a callable entity invokes other callable entities, Polyspace makes certain assumptions to calculate whether there might be unhandled exceptions.
Functions: When a noexcept function calls another function,
Polyspace checks whether the called function might raise an exception only if it
is specified as noexcept(<false>). If the called function is
specified as noexcept, Polyspace assumes that it does not raise an exception. Some standard library
functions, such as the constructor of std::string, use pointers to
functions to perform memory allocation, which might raise exceptions. Because these
functions are not specified as noexcept(<false>), Polyspace does not flag a function that calls these standard library
functions.
External function: When a noexcept function calls an external
function, Polyspace flags the function declaration if the external function is specified as
noexcept(<false>).
Virtual function: When a function calls a virtual function, Polyspace flags the function declaration if the virtual function is specified as
noexcept(<false>) in a derived class. For instance, if a
noexcept function calls a virtual function that is declared as
noexcept(<true>) in the base class, and
noexcept(<false>) in a subsequent derived class, Polyspace flags the declaration of the noexcept
function.
Pointers to function: When a noexcept function invokes a
pointer to a function, Polyspace assumes that the pointer to function does not raise exceptions.
When analyzing whether a function raises unhandled exceptions, Polyspace ignores:
Exceptions raised in destructors
Exceptions raised in atexit() operations
Polyspace also ignores the dynamic context when checking for exceptions. For instance, a function might raise unhandled exceptions that arise only in certain dynamic contexts. Polyspace flags such a function even if the exception might not be raised.
If you expect a rule violation but do not see it, refer to Coding Standard Violations Not Displayed.
| Group: Exception Handling |
| Category: Required, Automated |