add a simple check to warn people who type "=+" when they probably meant
"+=".


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@55131 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index 2bb3983..c7db342 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -1901,10 +1901,30 @@
   }
 
   AssignConvertType ConvTy;
-  if (compoundType.isNull())
+  if (compoundType.isNull()) {
+    // Simple assignment "x = y".
     ConvTy = CheckSingleAssignmentConstraints(lhsType, rex);
-  else
+    
+    // If the RHS is a unary plus or minus, check to see if they = and + are
+    // right next to each other.  If so, the user may have typo'd "x =+ 4"
+    // instead of "x += 4".
+    Expr *RHSCheck = rex;
+    if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(RHSCheck))
+      RHSCheck = ICE->getSubExpr();
+    if (UnaryOperator *UO = dyn_cast<UnaryOperator>(RHSCheck)) {
+      if ((UO->getOpcode() == UnaryOperator::Plus ||
+           UO->getOpcode() == UnaryOperator::Minus) &&
+          loc.isFileID() && UO->getOperatorLoc().isFileID() &&
+          // Only if the two operators are exactly adjacent.
+          loc.getFileLocWithOffset(1) == UO->getOperatorLoc())
+        Diag(loc, diag::warn_not_compound_assign,
+             UO->getOpcode() == UnaryOperator::Plus ? "+" : "-",
+             SourceRange(UO->getOperatorLoc(), UO->getOperatorLoc()));
+    }
+  } else {
+    // Compound assignment "x += y"
     ConvTy = CheckCompoundAssignmentConstraints(lhsType, rhsType);
+  }
 
   if (DiagnoseAssignmentResult(ConvTy, loc, lhsType, rhsType,
                                rex, "assigning"))