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

Roman Lebedev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 16 00:01:44 PDT 2018


lebedev.ri added a comment.

In https://reviews.llvm.org/D44883#1068400, @brooksmoses wrote:

> I have noticed two things when attempting to release LLVM with this revision internally at Google:
>
> 1. It's catching real bugs, all in constructors where someone wrote "member_ = member_" when they meant "member_ = member".


Nice, just like the one that caused me to write this :)

> 2. It's catching at least as many cases of tests where people are intentionally testing that self-assignment doesn't corrupt the data values.
> 
>   Thus, this seems valuable but problematic, and the problems mean that initially we're facing turning off -Wself-assign completely until this is resolved.  That's definitely an issue, and at least means that this needs to be placed under its own -W option.  And the real bugs it's finding seem to be very specific, and could be found by a more-focused warning.

See all the previous disscussion about that earlier in the differential / mail thread..
I guess some consensus needs to be found, and then i'll implement it.

> EDIT: Looks like "var = *&var" is supposed to avoid the warning, so my (now-deleted) complaints about this not having a source workaround are erroneous.

See release notes.

> I still find the fact that "var = (var)" doesn't suppress this to be surprising, but it's not critical.


Repository:
  rC Clang

https://reviews.llvm.org/D44883





More information about the cfe-commits mailing list