AUTOSAR C++14 Rule A12-7-1
If the behavior of a user-defined special member function is identical to implicitly defined special member function, then it shall be defined "=default" or be left undefined
Since R2021b
Description
Rule Definition
If the behavior of a user-defined special member function is identical to implicitly defined special member function, then it shall be defined "=default" or be left undefined.
Rationale
Compilers implicitly define special member functions if these functions are declared as
=default
or left undefined. These implicitly defined functions are
consistent, error-free, and do not require maintenance. If the implicitly defined special
member functions are sufficient, then replacing them with user-defined functions makes the
code error-prone and harder to maintain. Unless a class manages resources like a raw pointer
or a POSIX file descriptor, the implicit definition of the special member functions might be
sufficient. Avoid defining the special member functions when the implicit definitions are
sufficient.
Default construction of const
objects might cause a compilation
failure if the nonstatic data members are not initialized during definition. The best
practice is to initialize nonstatic data members in the class definition. Alternatively,
initialize the const
instance by using an empty initializer list. These
practices enable the default constructor to correctly construct const
instances of a class.
Polyspace Implementation
Polyspace® raises the checker if the user-defined special member functions of your class are the same as the implicitly defined special member functions. The implicit special member functions typically have these properties:
The implicit default constructor have an empty body, an empty parameter list, and an empty initializer list.
The implicit destructors have an empty body.
The implicit copy/move constructor and assignment operators copy/move the base classes and nonstatic data members by using an initializer list. These functions does not perform any deep copy and does not move the data associated with a raw pointer.
For details about how implicitly defined special member function behave, see:
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: Special member functions |
Category: Required, Automated |