AUTOSAR C++14 Rule A12-8-6
Copy and move constructors and copy assignment and move assignment operators shall be declared protected or defined "=delete" in base class
Since R2020a
Description
Rule Definition
Copy and move constructors and copy assignment and move assignment operators shall be declared protected or defined "=delete" in base class.
Rationale
Pointers to derived classes are type-compatible with pointers to base classes. A pointer can be an object of the base class while pointing to an object of the derived class. When such an object is copied, the base copy constructor is invoked and the copied object has only the base part of the original object. To avoid inadvertent slicing during copy and move, suppress these operations in the base class by:
Declaring copy and move constructors and copy assignment and move assignment operators as
protected
.Defining copy and move constructors and copy assignment and move assignment operators as "
=delete
".
Polyspace Implementation
Polyspace® flags these special member functions of a base class when they are not
declared protected
or defined as =delete
:
Copy constructor
Move constructor
Copy assignment operator
Move assignment operator
Polyspace indicates which special member function violates this rule.
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 |
Version History
Introduced in R2020a