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

John McCall via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 26 00:18:49 PDT 2018


rjmccall added a comment.

I'm not sure you really need to put these in their own warning sub-group just because they're user-defined operators.  That's especially true because it appears we already have divisions in the warning group based on the form of the l-value; we don't want this to go combinatorial.



================
Comment at: lib/Sema/SemaExpr.cpp:12087
+  case BO_AndAssign:
+  case BO_OrAssign:
+    DiagnoseSelfAssignment(S, LHS, RHS, OpLoc, /*IsBuiltin=*/false);
----------------
Quuxplusone wrote:
> I understand why `x &= x` and `x |= x` are mathematically special for the built-in types, but surely `x -= x` and `x ^= x` and `x /= x` are just as likely to indicate programmer error. I would be happy if Clang either took the philosophical stance "We will diagnose `x = x` but uniformly //never// `x op= x`," or else took the pragmatic stance "We will diagnose any `x op= x` or `x op x` that seems likely to be a programming bug." This "middle way" of warning only for `&=` and `|=` is bothersome to me.
I think "we want to diagnose anything that seems likely to be a programming bug" is already our policy here.  It's inevitable that we'll overlook examples of that.  I agree that we should apply this warning to at least -=, ^=, and /=.


Repository:
  rC Clang

https://reviews.llvm.org/D44883





More information about the cfe-commits mailing list