[PATCH] PR12214 - warn on suspicious self-compound-assignments

Nikola Smiljanić popizdeh at gmail.com
Sun May 25 18:39:01 PDT 2014


Now with tests.

http://reviews.llvm.org/D3753

Files:
  lib/Sema/SemaExpr.cpp
  test/SemaCXX/warn-self-assign.cpp

Index: lib/Sema/SemaExpr.cpp
===================================================================
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -9313,8 +9313,9 @@
       ResultTy = CheckAssignmentOperands(LHS.get(), RHS, OpLoc, CompResultTy);
     break;
   case BO_AndAssign:
+  case BO_OrAssign: // fallthrough
+	  DiagnoseSelfAssignment(*this, LHS.get(), RHS.get(), OpLoc);
   case BO_XorAssign:
-  case BO_OrAssign:
     CompResultTy = CheckBitwiseOperands(LHS, RHS, OpLoc, true);
     CompLHSTy = CompResultTy;
     if (!CompResultTy.isNull() && !LHS.isInvalid() && !RHS.isInvalid())
Index: test/SemaCXX/warn-self-assign.cpp
===================================================================
--- test/SemaCXX/warn-self-assign.cpp
+++ test/SemaCXX/warn-self-assign.cpp
@@ -8,6 +8,9 @@
   b = a = b;
   a = a = a; // expected-warning{{explicitly assigning}}
   a = b = b = a;
+  a &= a; // expected-warning{{explicitly assigning}}
+  a |= a; // expected-warning{{explicitly assigning}}
+  a ^= a;
 }
 
 // Dummy type.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D3753.9791.patch
Type: text/x-patch
Size: 1030 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140526/8247440d/attachment.bin>


More information about the cfe-commits mailing list