Skip to content

Commit 12f29f2

Browse files
committed
Closes #1647
1 parent 895d709 commit 12f29f2

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

CppCoreGuidelines.md

+11-15
Original file line numberDiff line numberDiff line change
@@ -4490,7 +4490,7 @@ By default, C++ treats classes as value-like types, but not all types are value-
44904490
Set of default operations rules:
44914491

44924492
* [C.20: If you can avoid defining any default operations, do](#Rc-zero)
4493-
* [C.21: If you define or `=delete` any default operation, define or `=delete` them all](#Rc-five)
4493+
* [C.21: If you define or `=delete` any copy, move, or destructor function, define or `=delete` them all](#Rc-five)
44944494
* [C.22: Make default operations consistent](#Rc-matched)
44954495

44964496
Destructor rules:
@@ -4578,29 +4578,25 @@ This is known as "the rule of zero".
45784578
(Not enforceable) While not enforceable, a good static analyzer can detect patterns that indicate a possible improvement to meet this rule.
45794579
For example, a class with a (pointer, size) pair of member and a destructor that `delete`s the pointer could probably be converted to a `vector`.
45804580

4581-
### <a name="Rc-five"></a>C.21: If you define or `=delete` any default operation, define or `=delete` them all
4581+
### <a name="Rc-five"></a>C.21: If you define or `=delete` any copy, move, or destructor function, define or `=delete` them all
45824582

45834583
##### Reason
45844584

4585-
The *special member functions* are the default constructor, copy constructor,
4586-
copy assignment operator, move constructor, move assignment operator, and
4587-
destructor.
4585+
The semantics of copy, move, and destruction are closely related, so if one needs to be declared, the odds are that others need consideration too.
45884586

4589-
The semantics of the special functions are closely related, so if one needs to be declared, the odds are that others need consideration too.
4590-
4591-
Declaring any special member function except a default constructor,
4587+
Declaring any copy/move/destructor function,
45924588
even as `=default` or `=delete`, will suppress the implicit declaration
45934589
of a move constructor and move assignment operator.
45944590
Declaring a move constructor or move assignment operator, even as
45954591
`=default` or `=delete`, will cause an implicitly generated copy constructor
45964592
or implicitly generated copy assignment operator to be defined as deleted.
4597-
So as soon as any of the special functions is declared, the others should
4593+
So as soon as any of these are declared, the others should
45984594
all be declared to avoid unwanted effects like turning all potential moves
45994595
into more expensive copies, or making a class move-only.
46004596

46014597
##### Example, bad
46024598

4603-
struct M2 { // bad: incomplete set of default operations
4599+
struct M2 { // bad: incomplete set of copy/move/destructor operations
46044600
public:
46054601
// ...
46064602
// ... no copy or move operations ...
@@ -4622,12 +4618,12 @@ Given that "special attention" was needed for the destructor (here, to deallocat
46224618

46234619
##### Note
46244620

4625-
This is known as "the rule of five" or "the rule of six", depending on whether you count the default constructor.
4621+
This is known as "the rule of five."
46264622

46274623
##### Note
46284624

4629-
If you want a default implementation of a default operation (while defining another), write `=default` to show you're doing so intentionally for that function.
4630-
If you don't want a default operation, suppress it with `=delete`.
4625+
If you want a default implementation (while defining another), write `=default` to show you're doing so intentionally for that function.
4626+
If you don't want a generated default function, suppress it with `=delete`.
46314627

46324628
##### Example, good
46334629

@@ -4672,7 +4668,7 @@ Relying on an implicitly generated copy operation in a class with a destructor i
46724668

46734669
##### Note
46744670

4675-
Writing the six special member functions can be error prone.
4671+
Writing these functions can be error prone.
46764672
Note their argument types:
46774673

46784674
class X {
@@ -4690,7 +4686,7 @@ To avoid the tedium and the possibility of errors, try to follow the [rule of ze
46904686

46914687
##### Enforcement
46924688

4693-
(Simple) A class should have a declaration (even a `=delete` one) for either all or none of the special functions.
4689+
(Simple) A class should have a declaration (even a `=delete` one) for either all or none of the copy/move/destructor functions.
46944690

46954691
### <a name="Rc-matched"></a>C.22: Make default operations consistent
46964692

0 commit comments

Comments
 (0)