diff --git a/googlemock/include/gmock/gmock-more-actions.h b/googlemock/include/gmock/gmock-more-actions.h index dd90e31f..e341d47f 100644 --- a/googlemock/include/gmock/gmock-more-actions.h +++ b/googlemock/include/gmock/gmock-more-actions.h @@ -592,8 +592,9 @@ namespace internal { // Overloads for other custom-callables are provided in the // internal/custom/gmock-generated-actions.h header. template -auto InvokeArgument(F f, Args... args) -> decltype(f(args...)) { - return f(args...); +auto InvokeArgument(F &&f, + Args... args) -> decltype(std::forward(f)(args...)) { + return std::forward(f)(args...); } template diff --git a/googlemock/test/gmock-more-actions_test.cc b/googlemock/test/gmock-more-actions_test.cc index 16af6892..7ed89a98 100644 --- a/googlemock/test/gmock-more-actions_test.cc +++ b/googlemock/test/gmock-more-actions_test.cc @@ -91,6 +91,10 @@ struct UnaryMoveOnlyFunctor : UnaryFunctor { UnaryMoveOnlyFunctor(UnaryMoveOnlyFunctor&&) = default; }; +struct OneShotUnaryFunctor { + int operator()(bool x) && { return x ? 1 : -1; } +}; + const char* Binary(const char* input, short n) { return input + n; } // NOLINT int Ternary(int x, char y, short z) { return x + y + z; } // NOLINT @@ -716,6 +720,12 @@ TEST(InvokeArgumentTest, Functor1MoveOnly) { EXPECT_EQ(1, a.Perform(std::make_tuple(UnaryMoveOnlyFunctor()))); } +// Tests using InvokeArgument with a one-shot unary functor. +TEST(InvokeArgumentTest, OneShotFunctor1) { + Action a = InvokeArgument<0>(true); // NOLINT + EXPECT_EQ(1, a.Perform(std::make_tuple(OneShotUnaryFunctor()))); +} + // Tests using InvokeArgument with a 5-ary function. TEST(InvokeArgumentTest, Function5) { Action a = // NOLINT