Added C.12 to discourage const/reference data members

Would have been nice to put this after C.9 but item numbers are dense
around here.
This commit is contained in:
Herb Sutter 2021-04-01 12:12:03 -07:00
parent 4498e078e7
commit 77b4175785

View File

@ -4420,6 +4420,7 @@ Concrete type rule summary:
* [C.10: Prefer concrete types over class hierarchies](#Rc-concrete)
* [C.11: Make concrete types regular](#Rc-regular)
* [C.12: Don't make data members `const` or references](#Rc-constref)
### <a name="Rc-concrete"></a>C.10: Prefer concrete types over class hierarchies
@ -4509,6 +4510,27 @@ Often, such types are referred to as "move-only types".
???
### <a name="Rc-constref"></a>C.12: Don't make data members `const` or references
##### Reason
They are not useful, and make types difficult to use by making them either uncopyable or partially uncopyable for subtle reasons.
##### Example; bad
class bad {
const int i; // bad
string& s; // bad
// ...
};
##### Enforcement
Flag a data member that is `const`, `&`, or `&&`.
## <a name="S-ctor"></a>C.ctor: Constructors, assignments, and destructors
These functions control the lifecycle of objects: creation, copy, move, and destruction.