This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: -Wclass-memaccess warning should be in -Wextra, not -Wall
- From: Martin Sebor <msebor at gmail dot com>
- To: Soul Studios <matt at soulstudios dot co dot nz>, gcc at gcc dot gnu dot org
- Date: Fri, 6 Jul 2018 10:53:45 -0600
- Subject: Re: -Wclass-memaccess warning should be in -Wextra, not -Wall
- References: <4a472907-9262-cc5d-cd6b-b003424fa971@soulstudios.co.nz>
On 07/05/2018 05:14 PM, Soul Studios wrote:
Simply because a struct has a constructor does not mean it isn't a
viable target/source for use with memcpy/memmove/memset.
As the documentation that Segher quoted explains, it does
mean exactly that.
Some classes have user-defined copy and default ctors with
the same effect as memcpy/memset. In modern C++ those ctors
should be defaulted (= default) and GCC should emit optimal
code for them. In fact, in loops they can result in more
efficient code than the equivalent memset/memcpy calls. In
any case, "native" operations lend themselves more readily
to code analysis than raw memory accesses and as a result
allow all compilers (not just GCC) do a better a job of
detecting bugs or performing interesting transformations
that they may not be able to do otherwise.
Having benchmarked the alternatives memcpy/memmove/memset definitely
makes a difference in various scenarios.
Please open bugs with small test cases showing
the inefficiencies so the optimizers can be improved.
Martin