The behavior is undefined when memcpy
, memmove
, or memset
are invoked with objects of non-trivially copyable
types.
Trivially copyable types include:
- scalar types
- trivially copyable classes
- arrays of these types
A class is trivially copyable when:
- all its non-static data members and base classes are trivially copyable types,
- it has no virtual functions or base classes,
- its destructor is trival,
- and one or more of the following special member functions is trivial, and the rest are deleted: copy constructor, move constructor, copy
assignment operator, and move assignment operator.
Note: a default implementation is always considered trivial, both when it is explicit (with = default
) or implicit (if the special
member function is omitted).