Fixed FunctionTypeLoc range for trailing return type.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@165974 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp
index 3ef4f38..3e4d92a 100644
--- a/lib/Parse/ParseDecl.cpp
+++ b/lib/Parse/ParseDecl.cpp
@@ -4582,7 +4582,10 @@
 
   Actions.ActOnStartFunctionDeclarator();
 
-  SourceLocation StartLoc, EndLoc;
+  /* LocalEndLoc is the end location for the local FunctionTypeLoc.
+     EndLoc is the end location for the function declarator.
+     They differ for trailing return types. */
+  SourceLocation StartLoc, LocalEndLoc, EndLoc;
   SourceLocation LParenLoc, RParenLoc;
   LParenLoc = Tracker.getOpenLocation();
   StartLoc = LParenLoc;
@@ -4595,6 +4598,7 @@
 
     Tracker.consumeClose();
     RParenLoc = Tracker.getCloseLocation();
+    LocalEndLoc = RParenLoc;
     EndLoc = RParenLoc;
   } else {
     if (Tok.isNot(tok::r_paren))
@@ -4607,6 +4611,7 @@
     // If we have the closing ')', eat it.
     Tracker.consumeClose();
     RParenLoc = Tracker.getCloseLocation();
+    LocalEndLoc = RParenLoc;
     EndLoc = RParenLoc;
 
     if (getLangOpts().CPlusPlus) {
@@ -4663,13 +4668,15 @@
       MaybeParseCXX0XAttributes(FnAttrs);
 
       // Parse trailing-return-type[opt].
+      LocalEndLoc = EndLoc;
       if (getLangOpts().CPlusPlus0x && Tok.is(tok::arrow)) {
         Diag(Tok, diag::warn_cxx98_compat_trailing_return_type);
         if (D.getDeclSpec().getTypeSpecType() == TST_auto)
           StartLoc = D.getDeclSpec().getTypeSpecTypeLoc();
-        EndLoc = Tok.getLocation();
+        LocalEndLoc = Tok.getLocation();
         SourceRange Range;
         TrailingReturnType = ParseTrailingReturnType(Range);
+        EndLoc = Range.getEnd();
       }
     }
   }
@@ -4691,7 +4698,7 @@
                                              DynamicExceptions.size(),
                                              NoexceptExpr.isUsable() ?
                                                NoexceptExpr.get() : 0,
-                                             StartLoc, EndLoc, D,
+                                             StartLoc, LocalEndLoc, D,
                                              TrailingReturnType),
                 FnAttrs, EndLoc);