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)
llvm-svn: 209867

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

index d831008..209f425 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 1d4792e..9b4c638 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 fcdb2ab..7d558c6 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.