Change the error when a '+=' follows a declaration to suggest a fixit to '=' instead of just suggesting a ';'.

Old error:
plusequaldeclare1.cc:3:8: error: expected ';' at end of declaration
  int x += 6;
       ^
       ;

New error:
plusequaldeclare1.cc:3:9: error: invalid '+=' at end of declaration; did you
      mean '='?
  int x += 6;
        ^~
        =



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@148433 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp
index 1c7c45e..0de8c53 100644
--- a/lib/Parse/ParseDecl.cpp
+++ b/lib/Parse/ParseDecl.cpp
@@ -1269,8 +1269,12 @@
     D.getDeclSpec().getTypeSpecType() == DeclSpec::TST_auto;
 
   // Parse declarator '=' initializer.
-  if (isTokenEqualOrMistypedEqualEqual(
-                               diag::err_invalid_equalequal_after_declarator)) {
+  // If a '==' or '+=' is found, suggest a fixit to '='.
+  if (Tok.is(tok::equal) ||
+      CreateTokenReplacement(tok::equal, tok::equalequal,
+                             diag::err_invalid_equalequal_after_declarator) ||
+      CreateTokenReplacement(tok::equal, tok::plusequal,
+                             diag::err_invalid_plusequal_after_declarator)) {
     ConsumeToken();
     if (Tok.is(tok::kw_delete)) {
       if (D.isFunctionDeclarator())
diff --git a/lib/Parse/ParseExprCXX.cpp b/lib/Parse/ParseExprCXX.cpp
index f1cedfe..831c446 100644
--- a/lib/Parse/ParseExprCXX.cpp
+++ b/lib/Parse/ParseExprCXX.cpp
@@ -1259,8 +1259,12 @@
   ExprOut = ExprError();
 
   // '=' assignment-expression
-  if (isTokenEqualOrMistypedEqualEqual(
-                               diag::err_invalid_equalequal_after_declarator)) {
+  // If a '==' or '+=' is found, suggest a fixit to '='.
+  if (Tok.is(tok::equal) ||
+      CreateTokenReplacement(tok::equal, tok::equalequal,
+                             diag::err_invalid_equalequal_after_declarator) ||
+      CreateTokenReplacement(tok::equal, tok::plusequal,
+                             diag::err_invalid_plusequal_after_declarator)) {
     ConsumeToken();
     ExprResult AssignExpr(ParseAssignmentExpression());
     if (!AssignExpr.isInvalid()) 
diff --git a/lib/Parse/Parser.cpp b/lib/Parse/Parser.cpp
index 501e50c..6342b10 100644
--- a/lib/Parse/Parser.cpp
+++ b/lib/Parse/Parser.cpp
@@ -1401,18 +1401,21 @@
   return false;
 }
 
-bool Parser::isTokenEqualOrMistypedEqualEqual(unsigned DiagID) {
-  if (Tok.is(tok::equalequal)) {
-    // We have '==' in a context that we would expect a '='.
-    // The user probably made a typo, intending to type '='. Emit diagnostic,
-    // fixit hint to turn '==' -> '=' and continue as if the user typed '='.
-    Diag(Tok, DiagID)
-      << FixItHint::CreateReplacement(SourceRange(Tok.getLocation()),
-                                      getTokenSimpleSpelling(tok::equal));
-    return true;
-  }
+bool Parser::CreateTokenReplacement(tok::TokenKind ExpectedToken,
+                                    tok::TokenKind FoundToken,
+                                    unsigned DiagID) {
+  if (Tok.isNot(FoundToken))
+    return false;
 
-  return Tok.is(tok::equal);
+  // We have FoundToken in a context that we would expect an ExpectedToken.
+  // The user probably made a typo, intending to type ExpectedToken.
+  // Emit diagnostic, fixit hint to turn ReplaceToken -> ExpectedToken
+  // and continue as if the user typed ExpectedToken.
+  Tok.setKind(ExpectedToken);
+  Diag(Tok, DiagID)
+    << FixItHint::CreateReplacement(SourceRange(Tok.getLocation()),
+                                    getTokenSimpleSpelling(ExpectedToken));
+  return true;
 }
 
 SourceLocation Parser::handleUnexpectedCodeCompletionToken() {