Rule Definition
Move constructor and move assignment operator are intended to be noexcept. If they throw exceptions, strong exception safety can not be guaranteed, because the original type values could be already modified or partially modified.
Remediation
DEclare them as noexcept
Violation Code Sample
class C3
{
public:
C3() = default;
C3(C3&& rhs) // Non-compliant - move constructor throws
{
// ...
throw std::runtime_error("Error");
}
C3& operator=(C3&& rhs) // Non-compliant - move assignment operator throws
{
// ...
throw std::runtime_error("Error");
return *this;
Fixed Code Sample
#include <stdexcept>
class C1
{
public:
C1() = default;
C1(C1&& rhs)
noexcept // Compliant - move constructor declared to be noexcept
{
}
C1& operator=(C1&& rhs) noexcept // Compliant - move assignment operator
// declared to be noexcept
{
return *this;
}
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”.
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.