https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89729
Bug ID: 89729 Summary: [g++ 8] -Wclass-memaccess warning Product: gcc Version: 8.3.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: chantry.xavier at gmail dot com Target Milestone: --- Created attachment 45975 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=45975&action=edit test case There are already many bugs about this one, but since I am not expert on C++, I would like to have your advice. g++ -std=gnu++98 -c -Wall memaccess-short.cc memaccess-short.cc: In function ‘void script_data_init_empty(script_data_t*)’: memaccess-short.cc:14:61: warning: ‘void* memset(void*, int, size_t)’ clearing an object of type ‘script_data_t’ {aka ‘struct script_data_t’} with no trivial copy-assignment; use value-initialization instead [-Wclass-memaccess] ({ (typeof(*(p)) *)memset((p), 0, sizeof(*(p)) * (count)); }) ^ memaccess-short.cc:19:5: note: in expansion of macro ‘p_clear’ p_clear(&d2, 1); ^~~~~~~ memaccess-short.cc:4:16: note: ‘script_data_t’ {aka ‘struct script_data_t’} declared here typedef struct script_data_t { ^~~~~~~~~~~~~ memaccess-short.cc:20:33: warning: ‘void* memcpy(void*, const void*, size_t)’ writing to an object of type ‘script_data_t’ {aka ‘struct script_data_t’} with no trivial copy-assignment [-Wclass-memaccess] memcpy(data, &d2, sizeof(d2)); ^ memaccess-short.cc:4:16: note: ‘script_data_t’ {aka ‘struct script_data_t’} declared here typedef struct script_data_t { ^~~~~~~~~~~~~ I know this is a mix of C and C++ code so not very clean. What's the correct way in gnu++98 to do this ? p_clear is in a C header, but I can either write a variant for C++ (using ifdef), or maybe even directly replace the p_clear calls from C++ files. The other bugs mention cast to void * as a workaround, this does seem to work, even with a simple C cast. Is this also acceptable in my case for both memset and memcpy ?