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
be considered?
E.g., given:
struct S
{
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.
Martin