AUTOSAR C++14 Rule A15-2-2
If a constructor is not noexcept and the constructor cannot finish object initialization, then it shall deallocate the object's resources and it shall throw an exception
Since R2021a
Description
Rule Definition
If a constructor is not noexcept and the constructor cannot finish object initialization, then it shall deallocate the object's resources and it shall throw an exception.
Rationale
When a constructor abruptly terminates due to unhandled exception or failed dynamic
resource allocation, it might leave some objects in a partially constructed object, which is
undefined behavior. Before raising exceptions in class constructors, deallocate the already
allocated resources. When allocating resources, specify the new operation
as std::nothrow. Alternatively, perform the resource allocation in a
try or function-try block to handle exceptions that
might arise from a failed allocation.
Polyspace Implementation
Polyspace® flags a throw or new statement outside a
try block in a non-noexcept class constructor if the
statement might result in resource leak. For instance:
A
throwstatement outside atryblock is flagged if the allocated resources are not deallocated before the statement.A
newstatement is flagged if there are more than onenewstatement in succession and the latter ones is not specified asstd::nothrowor wrapped in atryorfunction-tryblock.
Polyspace ignores classes that remain unused in your code.
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 |
Version History
Introduced in R2021a