https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81169
Bug ID: 81169
Summary: gcc 8.0dev -Wclass-memaccess illegitimate warning
related to volatile
Product: gcc
Version: 8.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: dudul04 at yahoo dot fr
Target Milestone: ---
With GCC r249467, the following snippet
{{{
#include <string.h>
struct mystruct
{
double x;
};
void zero(volatile mystruct* x, int n)
{
memset(static_cast<void*>(const_cast<mystruct*>(x)),
0, n*sizeof(mystruct));
}
}}}
causes
{{{
$ g++ -Wall test_memaccess.cpp -c
test_memaccess.cpp: In function 'void zero(volatile mystruct*, int)':
test_memaccess.cpp:11:33: warning: 'void* memset(void*, int, size_t)' clearing
an object of type 'volatile struct mystruct' with no trivial copy-assignment;
use assignment or value-initialization instead [-Wclass-memaccess]
0, n*sizeof(mystruct));
^
test_memaccess.cpp:3:8: note: 'volatile struct mystruct' declared here
struct mystruct
^~~~~~~~
}}}
Removing the volatile qualifier prevents the warning from being emitted.