diff --git a/googlemock/include/gmock/gmock-function-mocker.h b/googlemock/include/gmock/gmock-function-mocker.h index df2308f2b..2e86ea344 100644 --- a/googlemock/include/gmock/gmock-function-mocker.h +++ b/googlemock/include/gmock/gmock-function-mocker.h @@ -50,6 +50,9 @@ namespace internal { template using identity_t = T; +template +struct TypeTag {}; + template struct ThisRefAdjuster { template @@ -322,6 +325,12 @@ using internal::FunctionMocker; const ::testing::internal::WithoutMatchers&, \ GMOCK_PP_IF(_Constness, const, )::testing::internal::Function< \ GMOCK_PP_REMOVE_PARENS(_Signature)>*) const _RefSpec _NoexceptSpec; \ + ::testing::FunctionMocker& \ + gmock_get_mocker_##_MethodName( \ + ::testing::internal::TypeTag) const { \ + return GMOCK_MOCKER_(_N, _Constness, _MethodName); \ + } \ mutable ::testing::FunctionMocker \ GMOCK_MOCKER_(_N, _Constness, _MethodName) @@ -335,18 +344,23 @@ using internal::FunctionMocker; GMOCK_PP_IF(_Constness, const, ) \ _RefSpec _NoexceptSpec GMOCK_PP_IF(_Override, override, ) \ GMOCK_PP_IF(_Final, final, ) { \ - GMOCK_MOCKER_(_N, _Constness, _MethodName) \ - .SetOwnerAndName(this, #_MethodName); \ - return GMOCK_MOCKER_(_N, _Constness, _MethodName) \ - .Invoke(GMOCK_PP_REPEAT(GMOCK_INTERNAL_FORWARD_ARG, _Signature, _N)); \ + auto& mocker = gmock_get_mocker_##_MethodName( \ + ::testing::internal::TypeTag{}); \ + mocker.SetOwnerAndName(this, #_MethodName); \ + return mocker.Invoke( \ + GMOCK_PP_REPEAT(GMOCK_INTERNAL_FORWARD_ARG, _Signature, _N)); \ } \ ::testing::MockSpec \ _MockClass::gmock_##_MethodName( \ GMOCK_PP_REPEAT(GMOCK_INTERNAL_MATCHER_PARAMETER, _Signature, _N)) \ GMOCK_PP_IF(_Constness, const, ) _RefSpec { \ - GMOCK_MOCKER_(_N, _Constness, _MethodName).RegisterOwner(this); \ - return GMOCK_MOCKER_(_N, _Constness, _MethodName) \ - .With(GMOCK_PP_REPEAT(GMOCK_INTERNAL_MATCHER_ARGUMENT, , _N)); \ + auto& mocker = gmock_get_mocker_##_MethodName( \ + ::testing::internal::TypeTag{}); \ + mocker.RegisterOwner(this); \ + return mocker.With( \ + GMOCK_PP_REPEAT(GMOCK_INTERNAL_MATCHER_ARGUMENT, , _N)); \ } \ ::testing::MockSpec \ _MockClass::gmock_##_MethodName( \