summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarco Bubke <30830880+marbub@users.noreply.github.com>2018-10-02 15:31:21 (GMT)
committerGennadiy Civil <misterg@google.com>2018-10-02 17:03:35 (GMT)
commit77962730563eece3525f40b8769e4ca0c6baf64c (patch)
tree2a4381a3cc365bebba95e7c3bc2344ec8325f3ff
parent00938b2b228f3b70d3d9e51f29a1505bdad43f1e (diff)
downloadgoogletest-77962730563eece3525f40b8769e4ca0c6baf64c.zip
googletest-77962730563eece3525f40b8769e4ca0c6baf64c.tar.gz
googletest-77962730563eece3525f40b8769e4ca0c6baf64c.tar.bz2
Merge 86fe8a25eb5a6e4546f9e39cf23a5c764217bf85 into 440527a61e1c91188195f7de212c63c77e8f0a45
Closes #1867 PiperOrigin-RevId: 215392714
-rw-r--r--googlemock/include/gmock/gmock-generated-function-mockers.h58
-rw-r--r--googlemock/include/gmock/gmock-generated-function-mockers.h.pump2
-rw-r--r--googlemock/test/gmock-generated-function-mockers_test.cc11
3 files changed, 45 insertions, 26 deletions
diff --git a/googlemock/include/gmock/gmock-generated-function-mockers.h b/googlemock/include/gmock/gmock-generated-function-mockers.h
index 5792d3d..aab4582 100644
--- a/googlemock/include/gmock/gmock-generated-function-mockers.h
+++ b/googlemock/include/gmock/gmock-generated-function-mockers.h
@@ -1175,9 +1175,7 @@ class MockFunction<R(A0)> {
#if GTEST_HAS_STD_FUNCTION_
::std::function<R(A0)> AsStdFunction() {
- return [this](A0 a0) -> R {
- return this->Call(::std::move(a0));
- };
+ return [this](A0 a0) -> R { return this->Call(::std::forward<A0>(a0)); };
}
#endif // GTEST_HAS_STD_FUNCTION_
@@ -1195,7 +1193,7 @@ class MockFunction<R(A0, A1)> {
#if GTEST_HAS_STD_FUNCTION_
::std::function<R(A0, A1)> AsStdFunction() {
return [this](A0 a0, A1 a1) -> R {
- return this->Call(::std::move(a0), ::std::move(a1));
+ return this->Call(::std::forward<A0>(a0), ::std::forward<A1>(a1));
};
}
#endif // GTEST_HAS_STD_FUNCTION_
@@ -1214,7 +1212,8 @@ 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) -> R {
- return this->Call(::std::move(a0), ::std::move(a1), ::std::move(a2));
+ return this->Call(::std::forward<A0>(a0), ::std::forward<A1>(a1),
+ ::std::forward<A2>(a2));
};
}
#endif // GTEST_HAS_STD_FUNCTION_
@@ -1233,8 +1232,8 @@ 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) -> R {
- return this->Call(::std::move(a0), ::std::move(a1), ::std::move(a2),
- ::std::move(a3));
+ return this->Call(::std::forward<A0>(a0), ::std::forward<A1>(a1),
+ ::std::forward<A2>(a2), ::std::forward<A3>(a3));
};
}
#endif // GTEST_HAS_STD_FUNCTION_
@@ -1254,8 +1253,9 @@ 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) -> R {
- return this->Call(::std::move(a0), ::std::move(a1), ::std::move(a2),
- ::std::move(a3), ::std::move(a4));
+ return this->Call(::std::forward<A0>(a0), ::std::forward<A1>(a1),
+ ::std::forward<A2>(a2), ::std::forward<A3>(a3),
+ ::std::forward<A4>(a4));
};
}
#endif // GTEST_HAS_STD_FUNCTION_
@@ -1275,8 +1275,9 @@ 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) -> R {
- return this->Call(::std::move(a0), ::std::move(a1), ::std::move(a2),
- ::std::move(a3), ::std::move(a4), ::std::move(a5));
+ return this->Call(::std::forward<A0>(a0), ::std::forward<A1>(a1),
+ ::std::forward<A2>(a2), ::std::forward<A3>(a3),
+ ::std::forward<A4>(a4), ::std::forward<A5>(a5));
};
}
#endif // GTEST_HAS_STD_FUNCTION_
@@ -1296,8 +1297,10 @@ 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) -> R {
- return this->Call(::std::move(a0), ::std::move(a1), ::std::move(a2),
- ::std::move(a3), ::std::move(a4), ::std::move(a5), ::std::move(a6));
+ return this->Call(::std::forward<A0>(a0), ::std::forward<A1>(a1),
+ ::std::forward<A2>(a2), ::std::forward<A3>(a3),
+ ::std::forward<A4>(a4), ::std::forward<A5>(a5),
+ ::std::forward<A6>(a6));
};
}
#endif // GTEST_HAS_STD_FUNCTION_
@@ -1317,9 +1320,10 @@ 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) -> R {
- return this->Call(::std::move(a0), ::std::move(a1), ::std::move(a2),
- ::std::move(a3), ::std::move(a4), ::std::move(a5), ::std::move(a6),
- ::std::move(a7));
+ return this->Call(::std::forward<A0>(a0), ::std::forward<A1>(a1),
+ ::std::forward<A2>(a2), ::std::forward<A3>(a3),
+ ::std::forward<A4>(a4), ::std::forward<A5>(a5),
+ ::std::forward<A6>(a6), ::std::forward<A7>(a7));
};
}
#endif // GTEST_HAS_STD_FUNCTION_
@@ -1339,10 +1343,12 @@ 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) -> R {
- return this->Call(::std::move(a0), ::std::move(a1), ::std::move(a2),
- ::std::move(a3), ::std::move(a4), ::std::move(a5), ::std::move(a6),
- ::std::move(a7), ::std::move(a8));
+ A8 a8) -> R {
+ return this->Call(::std::forward<A0>(a0), ::std::forward<A1>(a1),
+ ::std::forward<A2>(a2), ::std::forward<A3>(a3),
+ ::std::forward<A4>(a4), ::std::forward<A5>(a5),
+ ::std::forward<A6>(a6), ::std::forward<A7>(a7),
+ ::std::forward<A8>(a8));
};
}
#endif // GTEST_HAS_STD_FUNCTION_
@@ -1362,11 +1368,13 @@ 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) -> R {
- return this->Call(::std::move(a0), ::std::move(a1), ::std::move(a2),
- ::std::move(a3), ::std::move(a4), ::std::move(a5), ::std::move(a6),
- ::std::move(a7), ::std::move(a8), ::std::move(a9));
+ return [this](A0 a0, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8,
+ A9 a9) -> R {
+ return this->Call(::std::forward<A0>(a0), ::std::forward<A1>(a1),
+ ::std::forward<A2>(a2), ::std::forward<A3>(a3),
+ ::std::forward<A4>(a4), ::std::forward<A5>(a5),
+ ::std::forward<A6>(a6), ::std::forward<A7>(a7),
+ ::std::forward<A8>(a8), ::std::forward<A9>(a9));
};
}
#endif // GTEST_HAS_STD_FUNCTION_
diff --git a/googlemock/include/gmock/gmock-generated-function-mockers.h.pump b/googlemock/include/gmock/gmock-generated-function-mockers.h.pump
index 82f9512..106abe8 100644
--- a/googlemock/include/gmock/gmock-generated-function-mockers.h.pump
+++ b/googlemock/include/gmock/gmock-generated-function-mockers.h.pump
@@ -320,7 +320,7 @@ class MockFunction;
$for i [[
$range j 0..i-1
$var ArgTypes = [[$for j, [[A$j]]]]
-$var ArgValues = [[$for j, [[::std::move(a$j)]]]]
+$var ArgValues = [[$for j, [[::std::forward<A$j>(a$j)]]]]
$var ArgDecls = [[$for j, [[A$j a$j]]]]
template <typename R$for j [[, typename A$j]]>
class MockFunction<R($ArgTypes)> {
diff --git a/googlemock/test/gmock-generated-function-mockers_test.cc b/googlemock/test/gmock-generated-function-mockers_test.cc
index f16833b..4c49069 100644
--- a/googlemock/test/gmock-generated-function-mockers_test.cc
+++ b/googlemock/test/gmock-generated-function-mockers_test.cc
@@ -617,6 +617,17 @@ TEST(MockFunctionTest, AsStdFunctionReturnsReference) {
value = 2;
EXPECT_EQ(2, ref);
}
+
+TEST(MockFunctionTest, AsStdFunctionWithReferenceParameter) {
+ MockFunction<int(int &)> foo;
+ auto call = [](const std::function<int(int& )> &f, int &i) {
+ return f(i);
+ };
+ int i = 42;
+ EXPECT_CALL(foo, Call(i)).WillOnce(Return(-1));
+ EXPECT_EQ(-1, call(foo.AsStdFunction(), i));
+}
+
#endif // GTEST_HAS_STD_FUNCTION_
struct MockMethodSizes0 {