https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94989
Bug ID: 94989 Summary: missing -Wclass-memaccess on calls to functions with attribute access Product: gcc Version: 10.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: msebor at gcc dot gnu.org Target Milestone: --- Passing the address of a nontrivial object to a function that takes a void*, especially one declared with attribute access indicating it writes into the object, should be diagnosed by -Wclass-memaccess for the same reason the same misuses are when they involve built-ins like memset and memcpy. The test case below shows that only the latter is the case. $ cat t.C && gcc -O2 -S -Wall t.C class C { int &r; C (); C (const C&); virtual ~C (); }; __attribute__ ((access (write_only, 1, 2))) void f (void*, int); void g (C &c) { __builtin_memset (&c, 0, sizeof c); // -Wclass-memaccess (good) } void h (C &c) { f (&c, sizeof c); // missing warning } t.C: In function ‘void g(C&)’: t.C:13:36: warning: ‘void* __builtin_memset(void*, int, long unsigned int)’ clearing an object of type ‘class C’ with no trivial copy-assignment [-Wclass-memaccess] 13 | __builtin_memset (&c, 0, sizeof c); // -Wclass-memaccess (good) | ^ t.C:1:7: note: ‘class C’ declared here 1 | class C { | ^