summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkosak@google.com <kosak@google.com@8415998a-534a-0410-bf83-d39667b30386>2015-07-24 20:05:26 +0000
committerkosak@google.com <kosak@google.com@8415998a-534a-0410-bf83-d39667b30386>2015-07-24 20:05:26 +0000
commitd8a7e6e6f2a70209c412f515bdd6a2e14a5fc1dd (patch)
tree098f954f33214584c47708af0ad665aec74da20b
parent9d21353a98386f09cd067988d8c7ca2f187bb20b (diff)
downloadgooglemock-d8a7e6e6f2a70209c412f515bdd6a2e14a5fc1dd.tar.gz
Explicitly specify return value for lambda in AsStdFunction() to ensure it
works properly where return type is a reference. git-svn-id: http://googlemock.googlecode.com/svn/trunk@548 8415998a-534a-0410-bf83-d39667b30386
-rw-r--r--include/gmock/gmock-generated-function-mockers.h22
-rw-r--r--include/gmock/gmock-generated-function-mockers.h.pump2
-rw-r--r--test/gmock-generated-function-mockers_test.cc10
3 files changed, 22 insertions, 12 deletions
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 @@ class MockFunction<R()> {
#if GTEST_HAS_STD_FUNCTION_
std::function<R()> AsStdFunction() {
- return [this]() {
+ return [this]() -> R {
return this->Call();
};
}
@@ -900,7 +900,7 @@ class MockFunction<R(A0)> {
#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 @@ class MockFunction<R(A0, A1)> {
#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 @@ class MockFunction<R(A0, A1, A2)> {
#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 @@ class MockFunction<R(A0, A1, A2, A3)> {
#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 @@ class MockFunction<R(A0, A1, A2, A3, A4)> {
#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 @@ class MockFunction<R(A0, A1, A2, A3, A4, A5)> {
#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 @@ class MockFunction<R(A0, A1, A2, A3, A4, A5, A6)> {
#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 @@ class MockFunction<R(A0, A1, A2, A3, A4, A5, A6, A7)> {
#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 @@ class MockFunction<R(A0, A1, A2, A3, A4, A5, A6, A7, A8)> {
#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 @@ class MockFunction<R(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9)> {
#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 @@ class MockFunction<R($ArgTypes)> {
#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 @@ TEST(MockFunctionTest, AsStdFunction) {
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