Rule Definition
Delete operators are typically called from destructors, and so a delete operator that throws an exception is likely to cause an exception to be thrown from a destructor.
Remediation
Specify them as noexcept
Violation Code Sample
Delete Operator:
static void operator delete(void* ptr, std::size_t sz)
{
// ...
throw std::runtime_error("Error"); // Non-compliant - operator delete
// exits with an exception
}
};
Fixed Code Sample
Delete Operator:
static void operator delete(void* ptr, std::size_t sz) noexcept(true)
{
// ...
throw std::runtime_error("Error");
};
Reference
AUTOSAR 2014 C++, A15-5-1: A class destructor, “delete” operators, move constructor, move assignment operator and “swap” function shall not exit with an exception. They shall be all specified as “noexcept”.
CERT C++ DCL57-CPP. Do not let exceptions escape from destructors or deallocation functions
Related Technologies
Technical Criterion
PCI-DSS4-Requirement-6.2.4 - Software engineering techniques or other methods are defined and in use by software development personnel to prevent or mitigate common software attacks and related vulnerabilities
About CAST Appmarq
CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.