Address items called out in Issue 1424 (#1539)

* Address items called out in Issue 1424

* Fix issues caught by CI

* Updates based on PR review
This commit is contained in:
Zachary Henkel 2019-11-21 13:28:59 -06:00 committed by Herb Sutter
parent fc32070096
commit 39b9ebdf86
2 changed files with 42 additions and 9 deletions

View File

@ -4512,6 +4512,7 @@ Other default operations rules:
* [C.86: Make `==` symmetric with respect of operand types and `noexcept`](#Rc-eq)
* [C.87: Beware of `==` on base classes](#Rc-eq-base)
* [C.89: Make a `hash` `noexcept`](#Rc-hash)
* [C.90: Rely on constructors and assignment operators, not memset and memcpy](#Rc-memset)
## <a name="SS-defop"></a>C.defop: Default Operations
@ -6539,6 +6540,37 @@ That tends to work better than "cleverness" for non-specialists.
* Flag throwing `hash`es.
### <a name="Rc-memset"></a>C.90: Rely on constructors and assignment operators, not `memset` and `memcpy`
##### Reason
The standard C++ mechanism to construct an instance of a type is to call its constructor. As specified in guideline [C.41](#Rc-complete): a constructor should create a fully initialized object. No additional initialization, such as by `memcpy`, should be required.
A type will provide a copy constructor and/or copy assignment operator to appropriately make a copy of the class, preserving the type's invariants. Using memcpy to copy a non-trivially copyable type has undefined behavior. Frequently this results in slicing, or data corruption.
##### Example, bad
struct base
{
virtual void update() = 0;
std::shared_ptr<int> sp;
};
struct derived : public base
{
void update() override {}
};
void init(derived& a)
{
memset(&a, 0, sizeof(derived));
}
void copy(derived& a, derived& b)
{
memcpy(&a, &b, sizeof(derived));
}
## <a name="SS-containers"></a>C.con: Containers and other resource handles
A container is an object holding a sequence of objects of some type; `std::vector` is the archetypical container.

View File

@ -301,6 +301,7 @@ md
memberinit
members'
memcmp
memcpy
memmove
memoization
memoized