diff --git a/googlemock/include/gmock/gmock-actions.h b/googlemock/include/gmock/gmock-actions.h index 72663c85..70c325a4 100644 --- a/googlemock/include/gmock/gmock-actions.h +++ b/googlemock/include/gmock/gmock-actions.h @@ -1079,9 +1079,9 @@ struct ReturnNewAction { template struct ReturnArgAction { template - auto operator()(const Args&... args) const -> - typename std::tuple_element>::type { - return std::get(std::tie(args...)); + auto operator()(Args&&... args) const -> decltype(std::get( + std::forward_as_tuple(std::forward(args)...))) { + return std::get(std::forward_as_tuple(std::forward(args)...)); } }; diff --git a/googlemock/test/gmock-more-actions_test.cc b/googlemock/test/gmock-more-actions_test.cc index 53bb029f..fdc8c709 100644 --- a/googlemock/test/gmock-more-actions_test.cc +++ b/googlemock/test/gmock-more-actions_test.cc @@ -462,6 +462,12 @@ TEST(ReturnArgActionTest, WorksForMultiArgStringArg2) { EXPECT_EQ("seven", a.Perform(std::make_tuple(5, 6, std::string("seven"), 8))); } +TEST(ReturnArgActionTest, WorksForNonConstRefArg0) { + const Action a = ReturnArg<0>(); + std::string s = "12345"; + EXPECT_EQ(&s, &a.Perform(std::forward_as_tuple(s))); +} + TEST(SaveArgActionTest, WorksForSameType) { int result = 0; const Action a1 = SaveArg<0>(&result);