[PATCH] D44883: [Sema] Extend -Wself-assign and -Wself-assign-field to warn on overloaded self-assignment (classes)

Nico Weber via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 16 11:16:39 PDT 2018


On Mon, Apr 16, 2018 at 5:11 AM, Roman Lebedev via Phabricator via
cfe-commits <cfe-commits at lists.llvm.org> wrote:

> lebedev.ri added a comment.
>
> Re false-positives - at least two [post-]reviewers need to agree on the
> way forward (see previous comments, mail thread), and then i will implement
> it.
>
> In https://reviews.llvm.org/D44883#1068576, @brooksmoses wrote:
>
> > A further concern about this in the general case from the reviewer of
> one of my test-cleanup changes: The "var = *&var" idiom is not necessarily
> equivalent to "var = var" in cases of user-defined types, because operator&
> may be overloaded.
>
>
> Release notes state:
>
>   If you are doing such an assignment intentionally, e.g. in a unit test
> for
>   a data structure, the warning can be suppressed by adding ``*&`` to the
>   right-hand side or casting it to the appropriate reference type.
>
> So it could also be `var = static_cast<decltype(var) &>(var);`
>

Most people using clang won't read release notes. Maybe this could print a
"to silence this warning, insert *&" fixit note, like many other warnings
do.

I think of the 3 points you mention, "separate flag for this" is probably
the way to go.


>
>
> Repository:
>   rC Clang
>
> https://reviews.llvm.org/D44883
>
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180416/50db20c4/attachment.html>


More information about the llvm-commits mailing list