https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77307
Bug ID: 77307
Summary: Bring memset + free optimisation to C++
Product: gcc
Version: 6.1.1
Status: UNCONFIRMED
Severity: enhancement
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: jpakkane at gmail dot com
Target Milestone: ---
For the following code gcc will remove the call to memset:
void destroy(char *buf, size_t bufsize) {
memset(buf, 0, bufsize);
free(buf);
}
However if you change it to delete[] like this:
void destroy(char *buf, size_t bufsize) {
memset(buf, 0, bufsize);
delete[] buf;
}
memset is called. Tested on gcc.godbolt.org, Clang and ICC seem to behave in
the same way.
In this case there are no destructors to run so the reasoning for removing the
memset call should be the same for both cases (assuming the C++ standard does
not have some weird requirements of which I am unaware).