-Wclass-memaccess warning should be in -Wextra, not -Wall
Marc Glisse
marc.glisse@inria.fr
Tue Jul 10 08:10:00 GMT 2018
On Mon, 9 Jul 2018, Martin Sebor wrote:
>> My point to all of this (and I'm annoyed that I'm having to repeat it
>> again, as it my first post wasn't clear enough - which it was) was that
>> any programmer using memcpy/memmove/memset is going to know what they're
>> getting into.
>
> No, programmers don't always know that. In fact, it's easy even
> for an expert programmer to make the mistake that what looks like
> a POD struct can safely be cleared by memset or copied by memcpy
> when doing so is undefined because one of the struct members is
> of a non-trivial type (such a container like string).
Indeed, especially since some other compilers have implemented string in a
way that is safe (even if theoretically UB) to memset/memcpy.
>> Therefore it makes no sense to penalize them by getting them to write
>> ugly, needless code - regardless of the surrounding politics/codewars.
>
> Quite a lot of thought and discussion went into the design and
> implementation of the warning, so venting your frustrations or
> insulting those of us involved in the process is unlikely to
> help you effect a change. To make a compelling argument you
> need to provide convincing evidence that we have missed
> an important use case. The best way to do that in this forum
> is with test cases and/or real world designs that are hampered
> by our choice. That's a high bar to meet for warnings whose
> documented purpose is to diagnose "constructions that some
> users consider questionable, and that are easy to avoid (or
> modify to prevent the warning)."
I guess the phrasing is a bit weak, "some users" obviously has to refer to
a significant proportion of users, "easy to avoid" cannot have too many
drawbacks (in particular, generated code should be of equivalent quality),
etc.
-Wclass-memaccess fits the "easy to avoid" quite well, since a simple cast
disables it. -Wmaybe-uninitialized is much worse: it produces many false
positives, that change with every release and are super hard to avoid. And
even in the "easy to avoid" category where we don't want to litter the
code with casts to quiet the warnings, I find -Wsign-compare way worse in
practice than -Wclass-memaccess.
--
Marc Glisse
More information about the Gcc
mailing list