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

Roman Lebedev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 16 02:11:10 PDT 2018


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);`


Repository:
  rC Clang

https://reviews.llvm.org/D44883





More information about the llvm-commits mailing list