rsmith added inline comments.
================ Comment at: clang/lib/Sema/SemaExpr.cpp:15656 case BO_XorAssign: - DiagnoseSelfAssignment(S, LHS, RHS, OpLoc, false); CheckIdentityFieldAssignment(LHS, RHS, OpLoc, S); break; ---------------- python3kgae wrote: > rsmith wrote: > > This is the same thing, but for `this->x += this->x`. I think we should > > also suppress those warnings for compound assignment, except when one of > > the operands is an implicit member access and one is an explicit member > > access (`this->x += x;` should still warn if the latter `x` is also > > interpreted as `this->x`). > For case like this: > > ``` > class Vector { > public: > Vector& operator+=(const Vector &v) { return *this; } > Vector& operator-=(const Vector &v) { return *this; } > }; > > class A { > public: > A(){} > Vector x; > void foo() { > this->x -= this->x; > this->x -= x; > this->x += this->x; > this->x += x; > } > }; > ``` > clang will report 2 warning: > > ``` > <source>:14:14: warning: assigning field to itself [-Wself-assign-field] > this->x -= this->x; > ^ > <source>:15:14: warning: assigning field to itself [-Wself-assign-field] > this->x -= x; > ``` > > Do you mean we should make it report warning on this->x -= x; and this->x += > x; ? Let's not add any new warnings. Pretend my comment was about `-=`, not `+=`. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D146897/new/ https://reviews.llvm.org/D146897 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits