Calling memset, memcpy, or similar to write to an object of a non-trivial type (such as one that defines a ctor or dtor, or has such a member) can break the invariants otherwise maintained by the class and cause undefined behavior. The motivating example that prompted this work was a review of a change that added to a plain old struct a new member with a ctor and dtor (in this instance the member was of type std::vector). To help catch problems of this sort some projects (such as GDB) have apparently even devised their own clever solutions to detect them: https://sourceware.org/ml/gdb-patches/2017-04/msg00378.html. The attached patch adds a new warning, -Wnon-trivial-memaccess, that has GCC detect these mistakes. The patch also fixes up a handful of instances of the problem in GCC. These instances correspond to the two patterns below: struct A { void *p; void foo (int n) { p = malloc (n); } ~A () { free (p); } }; void init (A *a) { memset (a, 0, sizeof *a); } and struct B { int i; ~A (); }; void copy (B *p, const B *q) { memcpy (p, q, sizeof *p); ... } These aren't undefined and the patch could be tweaked to allow them. I decided not to invest effort into it because, although not strictly erroneous, I think they represent poor practice. The code would be more clearly (and more in the spirit of "good" C++) written in terms of the default constructor and assignment operator. The first one like so: *a = A (); and the second one like so: *b = *q; Martin