AutosarC++17_10-A12.0.1¶
If a class declares a copy or move operation, or a destructor, either via “=default”, “=delete”, or via a user-provided declaration, then all others of these five special member functions shall be declared as well
Required inputs: IR
| Level | required |
|---|---|
| Target | implementation |
| Enforcement | automated |
Rationale
Semantics of all of the special member functions are closely related to each other.
If any special member function needs to be non-default, then all others need to be defined too.
Note that this rule is also known as “the rule of five” or “the rule of six”.
Also, note that the rule allows to follow “the rule of zero” for types that do not need to define any special member function.
Example
// $Id: A12-0-1.cpp 271696 2017-03-23 09:23:09Z piotr.tanski $
#include <cstdint>
class A // Compliant - the class A follow the "Rule of six" rule
{
public:
A(); // Non-default constructor
~A() = default;
A(A const &) = default;
A &operator=(A const &) = default;
A(A &&) = delete;
A &operator=(A &&) = delete;
};
class B // Non-compliant - some special functions are defined but not all of
// them
{
public:
B();
~B();
private:
std::int32_t *pointer;
};
struct C // Compliant - no special functions are defined
{
std::int32_t number;
};
See Also
- C++ Core Guidelines [10]: C.21: If you define or =delete any default operation, define or =delete them all.
- C++ Core Guidelines [10]: C.81: Use =delete when you want to disable default behavior (without wanting an alternative).
Possible Messages
Key |
Text |
Severity |
Disabled |
|---|---|---|---|
missing_declarations |
Class with special member function is missing {}. |
None |
False |
Options
This rule shares the following common options: confidence, exclude_in_macros, exclude_messages_in_system_headers, excludes, extend_exclude_to_macro_invocations, includes, justification_checker, languages, post_processing, provider, report_at, severity
The following places define options that affect this rule: Stylechecks, Analysis-GlobalOptions
This rule has no individual options.