This is the mail archive of the
mailing list for the GCC project.
Re: [PATCH] warn on mem calls modifying objects of non-trivial types (PR 80560)
- From: Martin Sebor <msebor at gmail dot com>
- To: Jason Merrill <jason at redhat dot com>
- Cc: Pedro Alves <palves at redhat dot com>, Gcc Patch List <gcc-patches at gcc dot gnu dot org>
- Date: Mon, 5 Jun 2017 13:13:05 -0600
- Subject: Re: [PATCH] warn on mem calls modifying objects of non-trivial types (PR 80560)
- Authentication-results: sourceware.org; auth=none
- References: <email@example.com> <firstname.lastname@example.org> <CADzB+2=O4oFJazNaGN_Qxas9SBE1phBKL8yKpSA=g+Y3bbEnsA@mail.gmail.com> <email@example.com> <CADzB+2=je+R9qoRkvcDa=JkbeSQMiQpvemB_5BddkuUgJTBa0A@mail.gmail.com> <firstname.lastname@example.org> <CADzB+2nrZv0xeujw2uMhmnXipy1hQ6W=SsTNwk2T9-jEcXGTGw@mail.gmail.com> <email@example.com> <CADzB+2=yUEhWgbAdR8o40ZN0sGzaU_LST-Abh5Fteaa7_hn9Ng@mail.gmail.com> <firstname.lastname@example.org> <email@example.com> <firstname.lastname@example.org> <email@example.com> <firstname.lastname@example.org> <email@example.com> <firstname.lastname@example.org> <email@example.com> <firstname.lastname@example.org>
On 06/05/2017 10:07 AM, Martin Sebor wrote:
Maybe I should use a different approach and instead of trying
to see if a function is deleted use trivially_xible to see if
it's usable. That will mean changing the diagnostics from
"with a deleted special function" to "without trivial special
function" but it will avoid calling synthesized_method_walk
while still avoiding giving bogus suggestions.
Actually, this would check for one possible argument type and not
others, so I think it's better to keep looking at the declarations. You
can do that by just looking them up (lookup_fnfields_slot) and iterating
over them, you don't need to call synthesized_method_walk.
You mean using trivially_xible might check assignability or copy
constructibility from const T& but not from T& (or the other way
around), and you think both (or perhaps even other forms) should
S& operator= (const S&) = default;
void operator= (S&) = delete;
void f (S *d, const S *s)
memcpy(d, s, sizeof *d); // don't warn here
void g (S *d, S *s)
memcpy(d, s, sizeof *d); // but warn here
And your suggestion is to iterate over the assignment operator
(and copy ctor) overloads for S looking for one that's trivial,
public, and not deleted?
If that's it, I was thinking of just checking for the const T&
overload (as if by using std::is_trivially_copy_assignable<T>()).
I don't mind trying the approach you suggest. It should be more
accurate. I just want to make sure we're on the same page.
Actually, after some more thought and testing the approach I have
a feeling that distinguishing between the two cases above is not
what you meant.
Classes that overload copy assignment or copy ctors on the constness
of the argument are tricky to begin with and using raw memory calls
on them seems suspect and worthy of a warning.
I'm guessing what you meant by "checking for one possible argument
type and not others" is actually checking to make sure all copy
assignment (and copy ctor) overloads are trivial, not jut some,
and at least one of them is accessible. I'll go with that unless
I hear otherwise.