You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CppCoreGuidelines.md
+11-15
Original file line number
Diff line number
Diff line change
@@ -4490,7 +4490,7 @@ By default, C++ treats classes as value-like types, but not all types are value-
4490
4490
Set of default operations rules:
4491
4491
4492
4492
* [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)
4494
4494
* [C.22: Make default operations consistent](#Rc-matched)
4495
4495
4496
4496
Destructor rules:
@@ -4578,29 +4578,25 @@ This is known as "the rule of zero".
4578
4578
(Not enforceable) While not enforceable, a good static analyzer can detect patterns that indicate a possible improvement to meet this rule.
4579
4579
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`.
4580
4580
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
4582
4582
4583
4583
##### Reason
4584
4584
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.
4588
4586
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,
4592
4588
even as `=default` or `=delete`, will suppress the implicit declaration
4593
4589
of a move constructor and move assignment operator.
4594
4590
Declaring a move constructor or move assignment operator, even as
4595
4591
`=default` or `=delete`, will cause an implicitly generated copy constructor
4596
4592
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
4598
4594
all be declared to avoid unwanted effects like turning all potential moves
4599
4595
into more expensive copies, or making a class move-only.
4600
4596
4601
4597
##### Example, bad
4602
4598
4603
-
struct M2 { // bad: incomplete set of default operations
4599
+
struct M2 { // bad: incomplete set of copy/move/destructor operations
4604
4600
public:
4605
4601
// ...
4606
4602
// ... no copy or move operations ...
@@ -4622,12 +4618,12 @@ Given that "special attention" was needed for the destructor (here, to deallocat
4622
4618
4623
4619
##### Note
4624
4620
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."
4626
4622
4627
4623
##### Note
4628
4624
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`.
4631
4627
4632
4628
##### Example, good
4633
4629
@@ -4672,7 +4668,7 @@ Relying on an implicitly generated copy operation in a class with a destructor i
4672
4668
4673
4669
##### Note
4674
4670
4675
-
Writing the six special member functions can be error prone.
4671
+
Writing these functions can be error prone.
4676
4672
Note their argument types:
4677
4673
4678
4674
class X {
@@ -4690,7 +4686,7 @@ To avoid the tedium and the possibility of errors, try to follow the [rule of ze
4690
4686
4691
4687
##### Enforcement
4692
4688
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.
4694
4690
4695
4691
### <a name="Rc-matched"></a>C.22: Make default operations consistent
0 commit comments