diff options
author | Piotr Nycz <piotrwn1@gmail.com> | 2019-10-22 16:41:35 (GMT) |
---|---|---|
committer | Piotr Nycz <piotrwn1@gmail.com> | 2019-10-22 16:41:35 (GMT) |
commit | 19a3bbce512dc2c4959769134fddd52b27989003 (patch) | |
tree | a56e57afead6bae309384c6c3c9d900cc2297282 | |
parent | b11fb80e9e94384589037ecd0595b96105906bbc (diff) | |
download | googletest-19a3bbce512dc2c4959769134fddd52b27989003.zip googletest-19a3bbce512dc2c4959769134fddd52b27989003.tar.gz googletest-19a3bbce512dc2c4959769134fddd52b27989003.tar.bz2 |
Added tests verifying that temporaries are accepted by ReturnRef
Issue no 2527
-rw-r--r-- | googlemock/test/gmock-actions_test.cc | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/googlemock/test/gmock-actions_test.cc b/googlemock/test/gmock-actions_test.cc index f63c8c5..99d273a 100644 --- a/googlemock/test/gmock-actions_test.cc +++ b/googlemock/test/gmock-actions_test.cc @@ -646,6 +646,30 @@ TEST(ReturnRefTest, IsCovariant) { EXPECT_EQ(&derived, &a.Perform(std::make_tuple())); } +namespace +{ +template <typename T, typename = decltype(ReturnRef(std::declval<T&&>()))> +bool CanCallReturnRef(T&&) { return true; } +bool CanCallReturnRef(Unused) { return false; } +} + +// Tests that ReturnRef(v) is not working with temporaries (T&&) +TEST(ReturnRefTest, WillNotAcceptTemporaryAkaRValueRef) { + int value = 13; + EXPECT_TRUE(CanCallReturnRef(value)); + EXPECT_FALSE(CanCallReturnRef(std::move(value))); + EXPECT_FALSE(CanCallReturnRef(value + 1)); + EXPECT_FALSE(CanCallReturnRef(123)); +} + +// Tests that ReturnRef(v) is not working with const temporaries (const T&&) +TEST(ReturnRefTest, WillNotAcceptConstTemporaryAkaContRValueRef) { + const int value = 42; + EXPECT_TRUE(CanCallReturnRef(value)); + EXPECT_FALSE(CanCallReturnRef(std::move(value))); +} + + // Tests that ReturnRefOfCopy(v) works for reference types. TEST(ReturnRefOfCopyTest, WorksForReference) { int n = 42; |