[PATCH] D146897: [clang:diagnostics] Turning off warn_self_assignment_overloaded for user-defined compound assignments
Xiang Li via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sat Mar 25 22:31:04 PDT 2023
python3kgae created this revision.
python3kgae added reviewers: rjmccall, Quuxplusone, riccibruno.
Herald added a project: All.
python3kgae requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
Fixes 42469 https://github.com/llvm/llvm-project/issues/42469
Only check self assignment on BO_Assign when BuildOverloadedBinOp.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D146897
Files:
clang/lib/Sema/SemaExpr.cpp
clang/test/SemaCXX/warn-self-assign-overloaded.cpp
Index: clang/test/SemaCXX/warn-self-assign-overloaded.cpp
===================================================================
--- clang/test/SemaCXX/warn-self-assign-overloaded.cpp
+++ 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
}
Index: clang/lib/Sema/SemaExpr.cpp
===================================================================
--- clang/lib/Sema/SemaExpr.cpp
+++ 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:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D146897.508377.patch
Type: text/x-patch
Size: 1418 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230326/71c864d2/attachment.bin>
More information about the cfe-commits
mailing list