[PATCH] relax -Wclass-memaccess for class members (PR 84850)

Jason Merrill jason@redhat.com
Tue Mar 20 21:55:00 GMT 2018


OK.

On Mon, Mar 19, 2018 at 10:06 PM, Martin Sebor <msebor@gmail.com> wrote:
> The -Wclass-memaccess warning makes an exception for ctors and
> dtors of non-trivial classes with no bases to avoid triggering
> for uses of raw memory functions with this as the destination.
> All other members as well as non-members trigger the warning.
>
> In bug 84850 the reporter shows that some code (squid in this
> case) calls memset(this, 0. ...) in both the copy assignment
> operator and the copy ctor as a short-hand to clear all trivial
> members without having to explicitly enumerate them.  A similar
> idiom has been seen in Firefox (some of the bugs linked from
> https://bugzilla.mozilla.org/show_bug.cgi?id=1411029).
>
> Since calling memset(this, 0, sizeof *this) from any non-static
> member of a non-trivial class containing no non-trivial members
> is safe, the attached patch relaxes the warning to allow this
> idiom.
>
> I also noticed that the exemption for ctors and dtors is overly
> permissive and causes the warning not to trigger for classes with
> no bases or virtual functions but containing non-trivial members.
> This is bug 84851.  Jakub suggested to fix just 84850 for GCC 8
> and defer 84851 to GCC 9, so the patch follows that suggestion.
> Fixing the latter is a matter of removing the block in
> warn_for_restrict() with the FIXME comment above it.
>
> Martin



More information about the Gcc-patches mailing list