In Parser::ParseDecltypeSpecifier, make sure the end location it returns
is at the end of parsed tokens when an error occurs, otherwise we'll hit
an assertion when trying to annotate the decltype tokens.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@166826 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Parse/ParseDeclCXX.cpp b/lib/Parse/ParseDeclCXX.cpp
index e656a6b..492250d 100644
--- a/lib/Parse/ParseDeclCXX.cpp
+++ b/lib/Parse/ParseDeclCXX.cpp
@@ -696,9 +696,22 @@
                                                  0, /*IsDecltype=*/true);
     Result = ParseExpression();
     if (Result.isInvalid()) {
-      SkipUntil(tok::r_paren);
       DS.SetTypeSpecError();
-      return StartLoc;
+      if (SkipUntil(tok::r_paren, /*StopAtSemi=*/true, /*DontConsume=*/true)) {
+        EndLoc = ConsumeParen();
+      } else {
+        assert(Tok.is(tok::semi));
+        if (PP.isBacktrackEnabled()) {
+          // Backtrack to get the location of the last token before the semi.
+          PP.RevertCachedTokens(2);
+          ConsumeToken(); // the semi.
+          EndLoc = ConsumeAnyToken();
+          assert(Tok.is(tok::semi));
+        } else {
+          EndLoc = Tok.getLocation();
+        }
+      }
+      return EndLoc;
     }
 
     // Match the ')'