]> granicus.if.org Git - clang/commitdiff
PR12214 - Warn on suspicious self-compound-assignments.
authorNikola Smiljanic <popizdeh@gmail.com>
Fri, 30 May 2014 00:15:04 +0000 (00:15 +0000)
committerNikola Smiljanic <popizdeh@gmail.com>
Fri, 30 May 2014 00:15:04 +0000 (00:15 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@209867 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaExpr.cpp
test/SemaCXX/warn-self-assign.cpp

index d831008b1bb566f5a02a75bb414dc85d8fc28d74..209f4259b93fcb5b1c0eeadbd2c4bc0abc0391d5 100644 (file)
@@ -4466,7 +4466,7 @@ def warn_addition_in_bitshift : Warning<
   "'%1' will be evaluated first">, InGroup<ShiftOpParentheses>;
 
 def warn_self_assignment : Warning<
-  "explicitly assigning a variable of type %0 to itself">,
+  "explicitly assigning value of variable of type %0 to itself">,
   InGroup<SelfAssignment>, DefaultIgnore;
 
 def warn_string_plus_int : Warning<
index 1d4792e9e05d75adaf35730c3076eeb5efeef879..9b4c6382dceff36ab7b21be51e44d29bc1a6cc29 100644 (file)
@@ -9297,8 +9297,9 @@ ExprResult Sema::CreateBuiltinBinOp(SourceLocation OpLoc,
       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 fcdb2ab6bc6390a97af31746c83c45129a377a59..7d558c6a073e834af152af956799aebc0c6f3e23 100644 (file)
@@ -8,6 +8,9 @@ void f() {
   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.