diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -15644,13 +15644,15 @@ Expr *LHS, Expr *RHS) { switch (Opc) { case BO_Assign: + // Skip diagnose on compound assignment. + DiagnoseSelfAssignment(S, LHS, RHS, OpLoc, false); + [[fallthrough]]; case BO_DivAssign: case BO_RemAssign: case BO_SubAssign: case BO_AndAssign: case BO_OrAssign: case BO_XorAssign: - DiagnoseSelfAssignment(S, LHS, RHS, OpLoc, false); CheckIdentityFieldAssignment(LHS, RHS, OpLoc, S); break; default: diff --git a/clang/test/SemaCXX/warn-self-assign-overloaded.cpp b/clang/test/SemaCXX/warn-self-assign-overloaded.cpp --- a/clang/test/SemaCXX/warn-self-assign-overloaded.cpp +++ b/clang/test/SemaCXX/warn-self-assign-overloaded.cpp @@ -53,15 +53,15 @@ #ifndef DUMMY a *= a; - a /= a; // expected-warning {{explicitly assigning}} - a %= a; // expected-warning {{explicitly assigning}} + a /= a; + a %= a; a += a; - a -= a; // expected-warning {{explicitly assigning}} + a -= a; a <<= a; a >>= a; - a &= a; // expected-warning {{explicitly assigning}} - a |= a; // expected-warning {{explicitly assigning}} - a ^= a; // expected-warning {{explicitly assigning}} + a &= a; + a |= a; + a ^= a; #endif }