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

Arthur O'Dwyer via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Mar 25 20:07:08 PDT 2018


Quuxplusone added inline comments.


================
Comment at: lib/Sema/SemaExpr.cpp:12087
+  case BO_AndAssign:
+  case BO_OrAssign:
+    DiagnoseSelfAssignment(S, LHS, RHS, OpLoc, /*IsBuiltin=*/false);
----------------
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.


Repository:
  rC Clang

https://reviews.llvm.org/D44883





More information about the cfe-commits mailing list