Explicitly specify return value for lambda in AsStdFunction() to ensure it
works properly where return type is a reference.
diff --git a/include/gmock/gmock-generated-function-mockers.h b/include/gmock/gmock-generated-function-mockers.h
index b98b471..4fa5ca9 100644
--- a/include/gmock/gmock-generated-function-mockers.h
+++ b/include/gmock/gmock-generated-function-mockers.h
@@ -881,7 +881,7 @@
 
 #if GTEST_HAS_STD_FUNCTION_
   std::function<R()> AsStdFunction() {
-    return [this]() {
+    return [this]() -> R {
       return this->Call();
     };
   }
@@ -900,7 +900,7 @@
 
 #if GTEST_HAS_STD_FUNCTION_
   std::function<R(A0)> AsStdFunction() {
-    return [this](A0 a0) {
+    return [this](A0 a0) -> R {
       return this->Call(a0);
     };
   }
@@ -919,7 +919,7 @@
 
 #if GTEST_HAS_STD_FUNCTION_
   std::function<R(A0, A1)> AsStdFunction() {
-    return [this](A0 a0, A1 a1) {
+    return [this](A0 a0, A1 a1) -> R {
       return this->Call(a0, a1);
     };
   }
@@ -938,7 +938,7 @@
 
 #if GTEST_HAS_STD_FUNCTION_
   std::function<R(A0, A1, A2)> AsStdFunction() {
-    return [this](A0 a0, A1 a1, A2 a2) {
+    return [this](A0 a0, A1 a1, A2 a2) -> R {
       return this->Call(a0, a1, a2);
     };
   }
@@ -957,7 +957,7 @@
 
 #if GTEST_HAS_STD_FUNCTION_
   std::function<R(A0, A1, A2, A3)> AsStdFunction() {
-    return [this](A0 a0, A1 a1, A2 a2, A3 a3) {
+    return [this](A0 a0, A1 a1, A2 a2, A3 a3) -> R {
       return this->Call(a0, a1, a2, a3);
     };
   }
@@ -977,7 +977,7 @@
 
 #if GTEST_HAS_STD_FUNCTION_
   std::function<R(A0, A1, A2, A3, A4)> AsStdFunction() {
-    return [this](A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) {
+    return [this](A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) -> R {
       return this->Call(a0, a1, a2, a3, a4);
     };
   }
@@ -997,7 +997,7 @@
 
 #if GTEST_HAS_STD_FUNCTION_
   std::function<R(A0, A1, A2, A3, A4, A5)> AsStdFunction() {
-    return [this](A0 a0, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) {
+    return [this](A0 a0, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) -> R {
       return this->Call(a0, a1, a2, a3, a4, a5);
     };
   }
@@ -1017,7 +1017,7 @@
 
 #if GTEST_HAS_STD_FUNCTION_
   std::function<R(A0, A1, A2, A3, A4, A5, A6)> AsStdFunction() {
-    return [this](A0 a0, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) {
+    return [this](A0 a0, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) -> R {
       return this->Call(a0, a1, a2, a3, a4, a5, a6);
     };
   }
@@ -1037,7 +1037,7 @@
 
 #if GTEST_HAS_STD_FUNCTION_
   std::function<R(A0, A1, A2, A3, A4, A5, A6, A7)> AsStdFunction() {
-    return [this](A0 a0, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) {
+    return [this](A0 a0, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) -> R {
       return this->Call(a0, a1, a2, a3, a4, a5, a6, a7);
     };
   }
@@ -1058,7 +1058,7 @@
 #if GTEST_HAS_STD_FUNCTION_
   std::function<R(A0, A1, A2, A3, A4, A5, A6, A7, A8)> AsStdFunction() {
     return [this](A0 a0, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7,
-        A8 a8) {
+        A8 a8) -> R {
       return this->Call(a0, a1, a2, a3, a4, a5, a6, a7, a8);
     };
   }
@@ -1080,7 +1080,7 @@
 #if GTEST_HAS_STD_FUNCTION_
   std::function<R(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9)> AsStdFunction() {
     return [this](A0 a0, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7,
-        A8 a8, A9 a9) {
+        A8 a8, A9 a9) -> R {
       return this->Call(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9);
     };
   }
diff --git a/include/gmock/gmock-generated-function-mockers.h.pump b/include/gmock/gmock-generated-function-mockers.h.pump
index b099676..811502d 100644
--- a/include/gmock/gmock-generated-function-mockers.h.pump
+++ b/include/gmock/gmock-generated-function-mockers.h.pump
@@ -274,7 +274,7 @@
 
 #if GTEST_HAS_STD_FUNCTION_
   std::function<R($ArgTypes)> AsStdFunction() {
-    return [this]($ArgDecls) {
+    return [this]($ArgDecls) -> R {
       return this->Call($ArgNames);
     };
   }
diff --git a/test/gmock-generated-function-mockers_test.cc b/test/gmock-generated-function-mockers_test.cc
index 18f19d8..a86a613 100644
--- a/test/gmock-generated-function-mockers_test.cc
+++ b/test/gmock-generated-function-mockers_test.cc
@@ -606,6 +606,16 @@
   EXPECT_EQ(-1, call(foo.AsStdFunction(), 1));
   EXPECT_EQ(-2, call(foo.AsStdFunction(), 2));
 }
+
+TEST(MockFunctionTest, AsStdFunctionReturnsReference) {
+  MockFunction<int&()> foo;
+  int value = 1;
+  EXPECT_CALL(foo, Call()).WillOnce(ReturnRef(value));
+  int& ref = foo.AsStdFunction()();
+  EXPECT_EQ(1, ref);
+  value = 2;
+  EXPECT_EQ(2, ref);
+}
 #endif  // GTEST_HAS_STD_FUNCTION_
 
 }  // namespace gmock_generated_function_mockers_test