Classes and class hierarchies
C.12
Don't make data members `const` or references in a copyable or movable type
Reason
const and reference data members are not useful in a copyable or movable type, and make such types difficult to use by making them at least partly uncopyable/unmovable for subtle reasons.
Example; bad
class bad {
const int i; // bad
string& s; // bad
// ...
};
The const and & data members make this class "only-sort-of-copyable" -- copy-constructible but not copy-assignable.
Note
If you need a member to point to something, use a pointer (raw or smart, and gsl::not_null if it should not be null) instead of a reference.
Enforcement
Flag a data member that is const, &, or && in a type that has any copy or move operation.