https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87427
Bug ID: 87427 Summary: -Wclass-memaccess improvement for POD with convenience initializer Product: gcc Version: 8.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: jengelh at inai dot de Target Milestone: --- #include <cstring> struct S { int z; S() { z = 1; } } s; int main() { memset(&s, 0, sizeof(s)); } The rationale of -Wclass-memaccess as presented in the manpage ("Modifying the representation of such objects may violate invariants maintained by member functions") is sound. For the 3-liner example though, it could be argued that member functions do not guarantee any invariant, given all member variables are public and kinda invite direct access. Would it be considered worthwhile to have a, say, -Wclass-memaccess=except-struct, to relax the warning for types that satisfy (standard_layout && (all members are public) && (all members are non-const))?