Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-11-04 10:05:13

0001 // Copyright 2007, Google Inc.
0002 // All rights reserved.
0003 //
0004 // Redistribution and use in source and binary forms, with or without
0005 // modification, are permitted provided that the following conditions are
0006 // met:
0007 //
0008 //     * Redistributions of source code must retain the above copyright
0009 // notice, this list of conditions and the following disclaimer.
0010 //     * Redistributions in binary form must reproduce the above
0011 // copyright notice, this list of conditions and the following disclaimer
0012 // in the documentation and/or other materials provided with the
0013 // distribution.
0014 //     * Neither the name of Google Inc. nor the names of its
0015 // contributors may be used to endorse or promote products derived from
0016 // this software without specific prior written permission.
0017 //
0018 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
0019 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
0020 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
0021 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
0022 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
0023 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
0024 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
0025 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
0026 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
0027 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
0028 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0029 
0030 // Google Mock - a framework for writing C++ mock classes.
0031 //
0032 // The ACTION* family of macros can be used in a namespace scope to
0033 // define custom actions easily.  The syntax:
0034 //
0035 //   ACTION(name) { statements; }
0036 //
0037 // will define an action with the given name that executes the
0038 // statements.  The value returned by the statements will be used as
0039 // the return value of the action.  Inside the statements, you can
0040 // refer to the K-th (0-based) argument of the mock function by
0041 // 'argK', and refer to its type by 'argK_type'.  For example:
0042 //
0043 //   ACTION(IncrementArg1) {
0044 //     arg1_type temp = arg1;
0045 //     return ++(*temp);
0046 //   }
0047 //
0048 // allows you to write
0049 //
0050 //   ...WillOnce(IncrementArg1());
0051 //
0052 // You can also refer to the entire argument tuple and its type by
0053 // 'args' and 'args_type', and refer to the mock function type and its
0054 // return type by 'function_type' and 'return_type'.
0055 //
0056 // Note that you don't need to specify the types of the mock function
0057 // arguments.  However rest assured that your code is still type-safe:
0058 // you'll get a compiler error if *arg1 doesn't support the ++
0059 // operator, or if the type of ++(*arg1) isn't compatible with the
0060 // mock function's return type, for example.
0061 //
0062 // Sometimes you'll want to parameterize the action.   For that you can use
0063 // another macro:
0064 //
0065 //   ACTION_P(name, param_name) { statements; }
0066 //
0067 // For example:
0068 //
0069 //   ACTION_P(Add, n) { return arg0 + n; }
0070 //
0071 // will allow you to write:
0072 //
0073 //   ...WillOnce(Add(5));
0074 //
0075 // Note that you don't need to provide the type of the parameter
0076 // either.  If you need to reference the type of a parameter named
0077 // 'foo', you can write 'foo_type'.  For example, in the body of
0078 // ACTION_P(Add, n) above, you can write 'n_type' to refer to the type
0079 // of 'n'.
0080 //
0081 // We also provide ACTION_P2, ACTION_P3, ..., up to ACTION_P10 to support
0082 // multi-parameter actions.
0083 //
0084 // For the purpose of typing, you can view
0085 //
0086 //   ACTION_Pk(Foo, p1, ..., pk) { ... }
0087 //
0088 // as shorthand for
0089 //
0090 //   template <typename p1_type, ..., typename pk_type>
0091 //   FooActionPk<p1_type, ..., pk_type> Foo(p1_type p1, ..., pk_type pk) { ... }
0092 //
0093 // In particular, you can provide the template type arguments
0094 // explicitly when invoking Foo(), as in Foo<long, bool>(5, false);
0095 // although usually you can rely on the compiler to infer the types
0096 // for you automatically.  You can assign the result of expression
0097 // Foo(p1, ..., pk) to a variable of type FooActionPk<p1_type, ...,
0098 // pk_type>.  This can be useful when composing actions.
0099 //
0100 // You can also overload actions with different numbers of parameters:
0101 //
0102 //   ACTION_P(Plus, a) { ... }
0103 //   ACTION_P2(Plus, a, b) { ... }
0104 //
0105 // While it's tempting to always use the ACTION* macros when defining
0106 // a new action, you should also consider implementing ActionInterface
0107 // or using MakePolymorphicAction() instead, especially if you need to
0108 // use the action a lot.  While these approaches require more work,
0109 // they give you more control on the types of the mock function
0110 // arguments and the action parameters, which in general leads to
0111 // better compiler error messages that pay off in the long run.  They
0112 // also allow overloading actions based on parameter types (as opposed
0113 // to just based on the number of parameters).
0114 //
0115 // CAVEAT:
0116 //
0117 // ACTION*() can only be used in a namespace scope as templates cannot be
0118 // declared inside of a local class.
0119 // Users can, however, define any local functors (e.g. a lambda) that
0120 // can be used as actions.
0121 //
0122 // MORE INFORMATION:
0123 //
0124 // To learn more about using these macros, please search for 'ACTION' on
0125 // https://github.com/google/googletest/blob/main/docs/gmock_cook_book.md
0126 
0127 // IWYU pragma: private, include "gmock/gmock.h"
0128 // IWYU pragma: friend gmock/.*
0129 
0130 #ifndef GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_
0131 #define GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_
0132 
0133 #ifndef _WIN32_WCE
0134 #include <errno.h>
0135 #endif
0136 
0137 #include <algorithm>
0138 #include <exception>
0139 #include <functional>
0140 #include <memory>
0141 #include <string>
0142 #include <tuple>
0143 #include <type_traits>
0144 #include <utility>
0145 
0146 #include "gmock/internal/gmock-internal-utils.h"
0147 #include "gmock/internal/gmock-port.h"
0148 #include "gmock/internal/gmock-pp.h"
0149 
0150 GTEST_DISABLE_MSC_WARNINGS_PUSH_(4100)
0151 
0152 namespace testing {
0153 
0154 // To implement an action Foo, define:
0155 //   1. a class FooAction that implements the ActionInterface interface, and
0156 //   2. a factory function that creates an Action object from a
0157 //      const FooAction*.
0158 //
0159 // The two-level delegation design follows that of Matcher, providing
0160 // consistency for extension developers.  It also eases ownership
0161 // management as Action objects can now be copied like plain values.
0162 
0163 namespace internal {
0164 
0165 // BuiltInDefaultValueGetter<T, true>::Get() returns a
0166 // default-constructed T value.  BuiltInDefaultValueGetter<T,
0167 // false>::Get() crashes with an error.
0168 //
0169 // This primary template is used when kDefaultConstructible is true.
0170 template <typename T, bool kDefaultConstructible>
0171 struct BuiltInDefaultValueGetter {
0172   static T Get() { return T(); }
0173 };
0174 template <typename T>
0175 struct BuiltInDefaultValueGetter<T, false> {
0176   static T Get() {
0177     Assert(false, __FILE__, __LINE__,
0178            "Default action undefined for the function return type.");
0179 #if defined(__GNUC__) || defined(__clang__)
0180     __builtin_unreachable();
0181 #elif defined(_MSC_VER)
0182     __assume(0);
0183 #else
0184     return Invalid<T>();
0185     // The above statement will never be reached, but is required in
0186     // order for this function to compile.
0187 #endif
0188   }
0189 };
0190 
0191 // BuiltInDefaultValue<T>::Get() returns the "built-in" default value
0192 // for type T, which is NULL when T is a raw pointer type, 0 when T is
0193 // a numeric type, false when T is bool, or "" when T is string or
0194 // std::string.  In addition, in C++11 and above, it turns a
0195 // default-constructed T value if T is default constructible.  For any
0196 // other type T, the built-in default T value is undefined, and the
0197 // function will abort the process.
0198 template <typename T>
0199 class [[nodiscard]] BuiltInDefaultValue {
0200  public:
0201   // This function returns true if and only if type T has a built-in default
0202   // value.
0203   static bool Exists() { return ::std::is_default_constructible<T>::value; }
0204 
0205   static T Get() {
0206     return BuiltInDefaultValueGetter<
0207         T, ::std::is_default_constructible<T>::value>::Get();
0208   }
0209 };
0210 
0211 // This partial specialization says that we use the same built-in
0212 // default value for T and const T.
0213 template <typename T>
0214 class [[nodiscard]] BuiltInDefaultValue<const T> {
0215  public:
0216   static bool Exists() { return BuiltInDefaultValue<T>::Exists(); }
0217   static T Get() { return BuiltInDefaultValue<T>::Get(); }
0218 };
0219 
0220 // This partial specialization defines the default values for pointer
0221 // types.
0222 template <typename T>
0223 class [[nodiscard]] BuiltInDefaultValue<T*> {
0224  public:
0225   static bool Exists() { return true; }
0226   static T* Get() { return nullptr; }
0227 };
0228 
0229 // The following specializations define the default values for
0230 // specific types we care about.
0231 #define GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(type, value) \
0232   template <>                                                     \
0233   class BuiltInDefaultValue<type> {                               \
0234    public:                                                        \
0235     static bool Exists() { return true; }                         \
0236     static type Get() { return value; }                           \
0237   }
0238 
0239 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(void, );  // NOLINT
0240 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(::std::string, "");
0241 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(bool, false);
0242 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(unsigned char, '\0');
0243 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(signed char, '\0');
0244 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(char, '\0');
0245 
0246 // There's no need for a default action for signed wchar_t, as that
0247 // type is the same as wchar_t for gcc, and invalid for MSVC.
0248 //
0249 // There's also no need for a default action for unsigned wchar_t, as
0250 // that type is the same as unsigned int for gcc, and invalid for
0251 // MSVC.
0252 #if GMOCK_WCHAR_T_IS_NATIVE_
0253 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(wchar_t, 0U);  // NOLINT
0254 #endif
0255 
0256 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(unsigned short, 0U);  // NOLINT
0257 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(signed short, 0);     // NOLINT
0258 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(unsigned int, 0U);
0259 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(signed int, 0);
0260 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(unsigned long, 0UL);     // NOLINT
0261 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(signed long, 0L);        // NOLINT
0262 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(unsigned long long, 0);  // NOLINT
0263 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(signed long long, 0);    // NOLINT
0264 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(float, 0);
0265 GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(double, 0);
0266 
0267 #undef GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_
0268 
0269 // Partial implementations of metaprogramming types from the standard library
0270 // not available in C++11.
0271 
0272 template <typename P>
0273 struct negation
0274     // NOLINTNEXTLINE
0275     : std::integral_constant<bool, bool(!P::value)> {};
0276 
0277 // Base case: with zero predicates the answer is always true.
0278 template <typename...>
0279 struct conjunction : std::true_type {};
0280 
0281 // With a single predicate, the answer is that predicate.
0282 template <typename P1>
0283 struct conjunction<P1> : P1 {};
0284 
0285 // With multiple predicates the answer is the first predicate if that is false,
0286 // and we recurse otherwise.
0287 template <typename P1, typename... Ps>
0288 struct conjunction<P1, Ps...>
0289     : std::conditional<bool(P1::value), conjunction<Ps...>, P1>::type {};
0290 
0291 template <typename...>
0292 struct disjunction : std::false_type {};
0293 
0294 template <typename P1>
0295 struct disjunction<P1> : P1 {};
0296 
0297 template <typename P1, typename... Ps>
0298 struct disjunction<P1, Ps...>
0299     // NOLINTNEXTLINE
0300     : std::conditional<!bool(P1::value), disjunction<Ps...>, P1>::type {};
0301 
0302 template <typename...>
0303 using void_t = void;
0304 
0305 // Detects whether an expression of type `From` can be implicitly converted to
0306 // `To` according to [conv]. In C++17, [conv]/3 defines this as follows:
0307 //
0308 //     An expression e can be implicitly converted to a type T if and only if
0309 //     the declaration T t=e; is well-formed, for some invented temporary
0310 //     variable t ([dcl.init]).
0311 //
0312 // [conv]/2 implies we can use function argument passing to detect whether this
0313 // initialization is valid.
0314 //
0315 // Note that this is distinct from is_convertible, which requires this be valid:
0316 //
0317 //     To test() {
0318 //       return declval<From>();
0319 //     }
0320 //
0321 // In particular, is_convertible doesn't give the correct answer when `To` and
0322 // `From` are the same non-moveable type since `declval<From>` will be an rvalue
0323 // reference, defeating the guaranteed copy elision that would otherwise make
0324 // this function work.
0325 //
0326 // REQUIRES: `From` is not cv void.
0327 template <typename From, typename To>
0328 struct is_implicitly_convertible {
0329  private:
0330   // A function that accepts a parameter of type T. This can be called with type
0331   // U successfully only if U is implicitly convertible to T.
0332   template <typename T>
0333   static void Accept(T);
0334 
0335   // A function that creates a value of type T.
0336   template <typename T>
0337   static T Make();
0338 
0339   // An overload be selected when implicit conversion from T to To is possible.
0340   template <typename T, typename = decltype(Accept<To>(Make<T>()))>
0341   static std::true_type TestImplicitConversion(int);
0342 
0343   // A fallback overload selected in all other cases.
0344   template <typename T>
0345   static std::false_type TestImplicitConversion(...);
0346 
0347  public:
0348   using type = decltype(TestImplicitConversion<From>(0));
0349   static constexpr bool value = type::value;
0350 };
0351 
0352 // Like std::invoke_result_t from C++17, but works only for objects with call
0353 // operators (not e.g. member function pointers, which we don't need specific
0354 // support for in OnceAction because std::function deals with them).
0355 template <typename F, typename... Args>
0356 using call_result_t = decltype(std::declval<F>()(std::declval<Args>()...));
0357 
0358 template <typename Void, typename R, typename F, typename... Args>
0359 struct is_callable_r_impl : std::false_type {};
0360 
0361 // Specialize the struct for those template arguments where call_result_t is
0362 // well-formed. When it's not, the generic template above is chosen, resulting
0363 // in std::false_type.
0364 template <typename R, typename F, typename... Args>
0365 struct is_callable_r_impl<void_t<call_result_t<F, Args...>>, R, F, Args...>
0366     : std::conditional<
0367           std::is_void<R>::value,  //
0368           std::true_type,          //
0369           is_implicitly_convertible<call_result_t<F, Args...>, R>>::type {};
0370 
0371 // Like std::is_invocable_r from C++17, but works only for objects with call
0372 // operators. See the note on call_result_t.
0373 template <typename R, typename F, typename... Args>
0374 using is_callable_r = is_callable_r_impl<void, R, F, Args...>;
0375 
0376 // Like std::as_const from C++17.
0377 template <typename T>
0378 typename std::add_const<T>::type& as_const(T& t) {
0379   return t;
0380 }
0381 
0382 }  // namespace internal
0383 
0384 // Specialized for function types below.
0385 template <typename F>
0386 class [[nodiscard]] OnceAction;
0387 
0388 // An action that can only be used once.
0389 //
0390 // This is accepted by WillOnce, which doesn't require the underlying action to
0391 // be copy-constructible (only move-constructible), and promises to invoke it as
0392 // an rvalue reference. This allows the action to work with move-only types like
0393 // std::move_only_function in a type-safe manner.
0394 //
0395 // For example:
0396 //
0397 //     // Assume we have some API that needs to accept a unique pointer to some
0398 //     // non-copyable object Foo.
0399 //     void AcceptUniquePointer(std::unique_ptr<Foo> foo);
0400 //
0401 //     // We can define an action that provides a Foo to that API. Because It
0402 //     // has to give away its unique pointer, it must not be called more than
0403 //     // once, so its call operator is &&-qualified.
0404 //     struct ProvideFoo {
0405 //       std::unique_ptr<Foo> foo;
0406 //
0407 //       void operator()() && {
0408 //         AcceptUniquePointer(std::move(Foo));
0409 //       }
0410 //     };
0411 //
0412 //     // This action can be used with WillOnce.
0413 //     EXPECT_CALL(mock, Call)
0414 //         .WillOnce(ProvideFoo{std::make_unique<Foo>(...)});
0415 //
0416 //     // But a call to WillRepeatedly will fail to compile. This is correct,
0417 //     // since the action cannot correctly be used repeatedly.
0418 //     EXPECT_CALL(mock, Call)
0419 //         .WillRepeatedly(ProvideFoo{std::make_unique<Foo>(...)});
0420 //
0421 // A less-contrived example would be an action that returns an arbitrary type,
0422 // whose &&-qualified call operator is capable of dealing with move-only types.
0423 template <typename Result, typename... Args>
0424 class [[nodiscard]] OnceAction<Result(Args...)> final {
0425  private:
0426   // True iff we can use the given callable type (or lvalue reference) directly
0427   // via StdFunctionAdaptor.
0428   template <typename Callable>
0429   using IsDirectlyCompatible = internal::conjunction<
0430       // The callable must be compatible with our signature.
0431       internal::is_callable_r<Result, std::decay_t<Callable>, Args...>,
0432       // It must be possible to capture the callable in StdFunctionAdaptor.
0433       std::is_constructible<std::decay_t<Callable>, Callable>>;
0434 
0435   // True iff we can use the given callable type via StdFunctionAdaptor once we
0436   // ignore incoming arguments.
0437   template <typename Callable>
0438   using IsCompatibleAfterIgnoringArguments = internal::conjunction<
0439       // The callable must be invocable with zero arguments, returning something
0440       // convertible to Result.
0441       internal::is_callable_r<Result, std::decay_t<Callable>>,
0442       // It must be possible to capture the callable in a lambda.
0443       std::is_constructible<std::decay_t<Callable>, Callable>>;
0444 
0445  public:
0446   // Construct from a callable that is directly compatible with our mocked
0447   // signature: it accepts our function type's arguments and returns something
0448   // convertible to our result type.
0449   template <typename Callable,
0450             typename std::enable_if<
0451                 internal::conjunction<
0452                     // Teach clang on macOS that we're not talking about a
0453                     // copy/move constructor here. Otherwise it gets confused
0454                     // when checking the is_constructible requirement of our
0455                     // traits above.
0456                     internal::negation<std::is_same<
0457                         OnceAction, typename std::decay<Callable>::type>>,
0458                     IsDirectlyCompatible<Callable>>  //
0459                 ::value,
0460                 int>::type = 0>
0461   OnceAction(Callable&& callable)  // NOLINT
0462       : function_(StdFunctionAdaptor<typename std::decay<Callable>::type>(
0463             {}, std::forward<Callable>(callable))) {}
0464 
0465   // As above, but for a callable that ignores the mocked function's arguments.
0466   template <typename Callable,
0467             typename std::enable_if<
0468                 internal::conjunction<
0469                     // Teach clang on macOS that we're not talking about a
0470                     // copy/move constructor here. Otherwise it gets confused
0471                     // when checking the is_constructible requirement of our
0472                     // traits above.
0473                     internal::negation<std::is_same<
0474                         OnceAction, typename std::decay<Callable>::type>>,
0475                     // Exclude callables for which the overload above works.
0476                     // We'd rather provide the arguments if possible.
0477                     internal::negation<IsDirectlyCompatible<Callable>>,
0478                     IsCompatibleAfterIgnoringArguments<Callable>>::value,
0479                 int>::type = 0>
0480   OnceAction(Callable&& callable)  // NOLINT
0481                                    // Call the constructor above with a callable
0482                                    // that ignores the input arguments.
0483       : OnceAction(IgnoreIncomingArguments<typename std::decay<Callable>::type>{
0484             std::forward<Callable>(callable)}) {}
0485 
0486   // We are naturally copyable because we store only an std::function, but
0487   // semantically we should not be copyable.
0488   OnceAction(const OnceAction&) = delete;
0489   OnceAction& operator=(const OnceAction&) = delete;
0490   OnceAction(OnceAction&&) = default;
0491 
0492   // Invoke the underlying action callable with which we were constructed,
0493   // handing it the supplied arguments.
0494   Result Call(Args... args) && {
0495     return function_(std::forward<Args>(args)...);
0496   }
0497 
0498  private:
0499   // An adaptor that wraps a callable that is compatible with our signature and
0500   // being invoked as an rvalue reference so that it can be used as an
0501   // StdFunctionAdaptor. This throws away type safety, but that's fine because
0502   // this is only used by WillOnce, which we know calls at most once.
0503   //
0504   // Once we have something like std::move_only_function from C++23, we can do
0505   // away with this.
0506   template <typename Callable>
0507   class StdFunctionAdaptor final {
0508    public:
0509     // A tag indicating that the (otherwise universal) constructor is accepting
0510     // the callable itself, instead of e.g. stealing calls for the move
0511     // constructor.
0512     struct CallableTag final {};
0513 
0514     template <typename F>
0515     explicit StdFunctionAdaptor(CallableTag, F&& callable)
0516         : callable_(std::make_shared<Callable>(std::forward<F>(callable))) {}
0517 
0518     // Rather than explicitly returning Result, we return whatever the wrapped
0519     // callable returns. This allows for compatibility with existing uses like
0520     // the following, when the mocked function returns void:
0521     //
0522     //     EXPECT_CALL(mock_fn_, Call)
0523     //         .WillOnce([&] {
0524     //            [...]
0525     //            return 0;
0526     //         });
0527     //
0528     // Such a callable can be turned into std::function<void()>. If we use an
0529     // explicit return type of Result here then it *doesn't* work with
0530     // std::function, because we'll get a "void function should not return a
0531     // value" error.
0532     //
0533     // We need not worry about incompatible result types because the SFINAE on
0534     // OnceAction already checks this for us. std::is_invocable_r_v itself makes
0535     // the same allowance for void result types.
0536     template <typename... ArgRefs>
0537     internal::call_result_t<Callable, ArgRefs...> operator()(
0538         ArgRefs&&... args) const {
0539       return std::move(*callable_)(std::forward<ArgRefs>(args)...);
0540     }
0541 
0542    private:
0543     // We must put the callable on the heap so that we are copyable, which
0544     // std::function needs.
0545     std::shared_ptr<Callable> callable_;
0546   };
0547 
0548   // An adaptor that makes a callable that accepts zero arguments callable with
0549   // our mocked arguments.
0550   template <typename Callable>
0551   struct IgnoreIncomingArguments {
0552     internal::call_result_t<Callable> operator()(Args&&...) {
0553       return std::move(callable)();
0554     }
0555 
0556     Callable callable;
0557   };
0558 
0559   std::function<Result(Args...)> function_;
0560 };
0561 
0562 // When an unexpected function call is encountered, Google Mock will
0563 // let it return a default value if the user has specified one for its
0564 // return type, or if the return type has a built-in default value;
0565 // otherwise Google Mock won't know what value to return and will have
0566 // to abort the process.
0567 //
0568 // The DefaultValue<T> class allows a user to specify the
0569 // default value for a type T that is both copyable and publicly
0570 // destructible (i.e. anything that can be used as a function return
0571 // type).  The usage is:
0572 //
0573 //   // Sets the default value for type T to be foo.
0574 //   DefaultValue<T>::Set(foo);
0575 template <typename T>
0576 class [[nodiscard]] DefaultValue {
0577  public:
0578   // Sets the default value for type T; requires T to be
0579   // copy-constructable and have a public destructor.
0580   static void Set(T x) {
0581     delete producer_;
0582     producer_ = new FixedValueProducer(x);
0583   }
0584 
0585   // Provides a factory function to be called to generate the default value.
0586   // This method can be used even if T is only move-constructible, but it is not
0587   // limited to that case.
0588   typedef T (*FactoryFunction)();
0589   static void SetFactory(FactoryFunction factory) {
0590     delete producer_;
0591     producer_ = new FactoryValueProducer(factory);
0592   }
0593 
0594   // Unsets the default value for type T.
0595   static void Clear() {
0596     delete producer_;
0597     producer_ = nullptr;
0598   }
0599 
0600   // Returns true if and only if the user has set the default value for type T.
0601   static bool IsSet() { return producer_ != nullptr; }
0602 
0603   // Returns true if T has a default return value set by the user or there
0604   // exists a built-in default value.
0605   static bool Exists() {
0606     return IsSet() || internal::BuiltInDefaultValue<T>::Exists();
0607   }
0608 
0609   // Returns the default value for type T if the user has set one;
0610   // otherwise returns the built-in default value. Requires that Exists()
0611   // is true, which ensures that the return value is well-defined.
0612   static T Get() {
0613     return producer_ == nullptr ? internal::BuiltInDefaultValue<T>::Get()
0614                                 : producer_->Produce();
0615   }
0616 
0617  private:
0618   class ValueProducer {
0619    public:
0620     virtual ~ValueProducer() = default;
0621     virtual T Produce() = 0;
0622   };
0623 
0624   class FixedValueProducer : public ValueProducer {
0625    public:
0626     explicit FixedValueProducer(T value) : value_(value) {}
0627     T Produce() override { return value_; }
0628 
0629    private:
0630     const T value_;
0631     FixedValueProducer(const FixedValueProducer&) = delete;
0632     FixedValueProducer& operator=(const FixedValueProducer&) = delete;
0633   };
0634 
0635   class FactoryValueProducer : public ValueProducer {
0636    public:
0637     explicit FactoryValueProducer(FactoryFunction factory)
0638         : factory_(factory) {}
0639     T Produce() override { return factory_(); }
0640 
0641    private:
0642     const FactoryFunction factory_;
0643     FactoryValueProducer(const FactoryValueProducer&) = delete;
0644     FactoryValueProducer& operator=(const FactoryValueProducer&) = delete;
0645   };
0646 
0647   static ValueProducer* producer_;
0648 };
0649 
0650 // This partial specialization allows a user to set default values for
0651 // reference types.
0652 template <typename T>
0653 class [[nodiscard]] DefaultValue<T&> {
0654  public:
0655   // Sets the default value for type T&.
0656   static void Set(T& x) {  // NOLINT
0657     address_ = &x;
0658   }
0659 
0660   // Unsets the default value for type T&.
0661   static void Clear() { address_ = nullptr; }
0662 
0663   // Returns true if and only if the user has set the default value for type T&.
0664   static bool IsSet() { return address_ != nullptr; }
0665 
0666   // Returns true if T has a default return value set by the user or there
0667   // exists a built-in default value.
0668   static bool Exists() {
0669     return IsSet() || internal::BuiltInDefaultValue<T&>::Exists();
0670   }
0671 
0672   // Returns the default value for type T& if the user has set one;
0673   // otherwise returns the built-in default value if there is one;
0674   // otherwise aborts the process.
0675   static T& Get() {
0676     return address_ == nullptr ? internal::BuiltInDefaultValue<T&>::Get()
0677                                : *address_;
0678   }
0679 
0680  private:
0681   static T* address_;
0682 };
0683 
0684 // This specialization allows DefaultValue<void>::Get() to
0685 // compile.
0686 template <>
0687 class [[nodiscard]] DefaultValue<void> {
0688  public:
0689   static bool Exists() { return true; }
0690   static void Get() {}
0691 };
0692 
0693 // Points to the user-set default value for type T.
0694 template <typename T>
0695 typename DefaultValue<T>::ValueProducer* DefaultValue<T>::producer_ = nullptr;
0696 
0697 // Points to the user-set default value for type T&.
0698 template <typename T>
0699 T* DefaultValue<T&>::address_ = nullptr;
0700 
0701 // Implement this interface to define an action for function type F.
0702 template <typename F>
0703 class [[nodiscard]] ActionInterface {
0704  public:
0705   typedef typename internal::Function<F>::Result Result;
0706   typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
0707 
0708   ActionInterface() = default;
0709   virtual ~ActionInterface() = default;
0710 
0711   // Performs the action.  This method is not const, as in general an
0712   // action can have side effects and be stateful.  For example, a
0713   // get-the-next-element-from-the-collection action will need to
0714   // remember the current element.
0715   virtual Result Perform(const ArgumentTuple& args) = 0;
0716 
0717  private:
0718   ActionInterface(const ActionInterface&) = delete;
0719   ActionInterface& operator=(const ActionInterface&) = delete;
0720 };
0721 
0722 template <typename F>
0723 class [[nodiscard]] Action;
0724 
0725 // An Action<R(Args...)> is a copyable and IMMUTABLE (except by assignment)
0726 // object that represents an action to be taken when a mock function of type
0727 // R(Args...) is called. The implementation of Action<T> is just a
0728 // std::shared_ptr to const ActionInterface<T>. Don't inherit from Action! You
0729 // can view an object implementing ActionInterface<F> as a concrete action
0730 // (including its current state), and an Action<F> object as a handle to it.
0731 template <typename R, typename... Args>
0732 class [[nodiscard]] Action<R(Args...)> {
0733  private:
0734   using F = R(Args...);
0735 
0736   // Adapter class to allow constructing Action from a legacy ActionInterface.
0737   // New code should create Actions from functors instead.
0738   struct ActionAdapter {
0739     // Adapter must be copyable to satisfy std::function requirements.
0740     ::std::shared_ptr<ActionInterface<F>> impl_;
0741 
0742     template <typename... InArgs>
0743     typename internal::Function<F>::Result operator()(InArgs&&... args) {
0744       return impl_->Perform(
0745           ::std::forward_as_tuple(::std::forward<InArgs>(args)...));
0746     }
0747   };
0748 
0749   template <typename G>
0750   using IsCompatibleFunctor = std::is_constructible<std::function<F>, G>;
0751 
0752  public:
0753   typedef typename internal::Function<F>::Result Result;
0754   typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
0755 
0756   // Constructs a null Action.  Needed for storing Action objects in
0757   // STL containers.
0758   Action() = default;
0759 
0760   // Construct an Action from a specified callable.
0761   // This cannot take std::function directly, because then Action would not be
0762   // directly constructible from lambda (it would require two conversions).
0763   template <
0764       typename G,
0765       typename = typename std::enable_if<internal::disjunction<
0766           IsCompatibleFunctor<G>, std::is_constructible<std::function<Result()>,
0767                                                         G>>::value>::type>
0768   Action(G&& fun) {  // NOLINT
0769     Init(::std::forward<G>(fun), IsCompatibleFunctor<G>());
0770   }
0771 
0772   // Constructs an Action from its implementation.
0773   explicit Action(ActionInterface<F>* impl)
0774       : fun_(ActionAdapter{::std::shared_ptr<ActionInterface<F>>(impl)}) {}
0775 
0776   // This constructor allows us to turn an Action<Func> object into an
0777   // Action<F>, as long as F's arguments can be implicitly converted
0778   // to Func's and Func's return type can be implicitly converted to F's.
0779   template <typename Func>
0780   Action(const Action<Func>& action)  // NOLINT
0781       : fun_(action.fun_) {}
0782 
0783   // Returns true if and only if this is the DoDefault() action.
0784   bool IsDoDefault() const { return fun_ == nullptr; }
0785 
0786   // Performs the action.  Note that this method is const even though
0787   // the corresponding method in ActionInterface is not.  The reason
0788   // is that a const Action<F> means that it cannot be re-bound to
0789   // another concrete action, not that the concrete action it binds to
0790   // cannot change state.  (Think of the difference between a const
0791   // pointer and a pointer to const.)
0792   Result Perform(ArgumentTuple args) const {
0793     if (IsDoDefault()) {
0794       internal::IllegalDoDefault(__FILE__, __LINE__);
0795     }
0796     return internal::Apply(fun_, ::std::move(args));
0797   }
0798 
0799   // An action can be used as a OnceAction, since it's obviously safe to call it
0800   // once.
0801   operator OnceAction<F>() const {  // NOLINT
0802     // Return a OnceAction-compatible callable that calls Perform with the
0803     // arguments it is provided. We could instead just return fun_, but then
0804     // we'd need to handle the IsDoDefault() case separately.
0805     struct OA {
0806       Action<F> action;
0807 
0808       R operator()(Args... args) && {
0809         return action.Perform(
0810             std::forward_as_tuple(std::forward<Args>(args)...));
0811       }
0812     };
0813 
0814     return OA{*this};
0815   }
0816 
0817  private:
0818   template <typename G>
0819   friend class Action;
0820 
0821   template <typename G>
0822   void Init(G&& g, ::std::true_type) {
0823     fun_ = ::std::forward<G>(g);
0824   }
0825 
0826   template <typename G>
0827   void Init(G&& g, ::std::false_type) {
0828     fun_ = IgnoreArgs<typename ::std::decay<G>::type>{::std::forward<G>(g)};
0829   }
0830 
0831   template <typename FunctionImpl>
0832   struct IgnoreArgs {
0833     template <typename... InArgs>
0834     Result operator()(const InArgs&...) const {
0835       return function_impl();
0836     }
0837     template <typename... InArgs>
0838     Result operator()(const InArgs&...) {
0839       return function_impl();
0840     }
0841 
0842     FunctionImpl function_impl;
0843   };
0844 
0845   // fun_ is an empty function if and only if this is the DoDefault() action.
0846   ::std::function<F> fun_;
0847 };
0848 
0849 // The PolymorphicAction class template makes it easy to implement a
0850 // polymorphic action (i.e. an action that can be used in mock
0851 // functions of than one type, e.g. Return()).
0852 //
0853 // To define a polymorphic action, a user first provides a COPYABLE
0854 // implementation class that has a Perform() method template:
0855 //
0856 //   class FooAction {
0857 //    public:
0858 //     template <typename Result, typename ArgumentTuple>
0859 //     Result Perform(const ArgumentTuple& args) const {
0860 //       // Processes the arguments and returns a result, using
0861 //       // std::get<N>(args) to get the N-th (0-based) argument in the tuple.
0862 //     }
0863 //     ...
0864 //   };
0865 //
0866 // Then the user creates the polymorphic action using
0867 // MakePolymorphicAction(object) where object has type FooAction.  See
0868 // the definition of Return(void) and SetArgumentPointee<N>(value) for
0869 // complete examples.
0870 template <typename Impl>
0871 class [[nodiscard]] PolymorphicAction {
0872  public:
0873   explicit PolymorphicAction(const Impl& impl) : impl_(impl) {}
0874 
0875   template <typename F>
0876   operator Action<F>() const {
0877     return Action<F>(new MonomorphicImpl<F>(impl_));
0878   }
0879 
0880  private:
0881   template <typename F>
0882   class MonomorphicImpl : public ActionInterface<F> {
0883    public:
0884     typedef typename internal::Function<F>::Result Result;
0885     typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
0886 
0887     explicit MonomorphicImpl(const Impl& impl) : impl_(impl) {}
0888 
0889     Result Perform(const ArgumentTuple& args) override {
0890       return impl_.template Perform<Result>(args);
0891     }
0892 
0893    private:
0894     Impl impl_;
0895   };
0896 
0897   Impl impl_;
0898 };
0899 
0900 // Creates an Action from its implementation and returns it.  The
0901 // created Action object owns the implementation.
0902 template <typename F>
0903 Action<F> MakeAction(ActionInterface<F>* impl) {
0904   return Action<F>(impl);
0905 }
0906 
0907 // Creates a polymorphic action from its implementation.  This is
0908 // easier to use than the PolymorphicAction<Impl> constructor as it
0909 // doesn't require you to explicitly write the template argument, e.g.
0910 //
0911 //   MakePolymorphicAction(foo);
0912 // vs
0913 //   PolymorphicAction<TypeOfFoo>(foo);
0914 template <typename Impl>
0915 inline PolymorphicAction<Impl> MakePolymorphicAction(const Impl& impl) {
0916   return PolymorphicAction<Impl>(impl);
0917 }
0918 
0919 namespace internal {
0920 
0921 // Helper struct to specialize ReturnAction to execute a move instead of a copy
0922 // on return. Useful for move-only types, but could be used on any type.
0923 template <typename T>
0924 struct ByMoveWrapper {
0925   explicit ByMoveWrapper(T value) : payload(std::move(value)) {}
0926   T payload;
0927 };
0928 
0929 // The general implementation of Return(R). Specializations follow below.
0930 template <typename R>
0931 class [[nodiscard]] ReturnAction final {
0932  public:
0933   explicit ReturnAction(R value) : value_(std::move(value)) {}
0934 
0935   template <typename U, typename... Args,
0936             typename = typename std::enable_if<conjunction<
0937                 // See the requirements documented on Return.
0938                 negation<std::is_same<void, U>>,  //
0939                 negation<std::is_reference<U>>,   //
0940                 std::is_convertible<R, U>,        //
0941                 std::is_move_constructible<U>>::value>::type>
0942   operator OnceAction<U(Args...)>() && {  // NOLINT
0943     return Impl<U>(std::move(value_));
0944   }
0945 
0946   template <typename U, typename... Args,
0947             typename = typename std::enable_if<conjunction<
0948                 // See the requirements documented on Return.
0949                 negation<std::is_same<void, U>>,   //
0950                 negation<std::is_reference<U>>,    //
0951                 std::is_convertible<const R&, U>,  //
0952                 std::is_copy_constructible<U>>::value>::type>
0953   operator Action<U(Args...)>() const {  // NOLINT
0954     return Impl<U>(value_);
0955   }
0956 
0957  private:
0958   // Implements the Return(x) action for a mock function that returns type U.
0959   template <typename U>
0960   class Impl final {
0961    public:
0962     // The constructor used when the return value is allowed to move from the
0963     // input value (i.e. we are converting to OnceAction).
0964     explicit Impl(R&& input_value)
0965         : state_(new State(std::move(input_value))) {}
0966 
0967     // The constructor used when the return value is not allowed to move from
0968     // the input value (i.e. we are converting to Action).
0969     explicit Impl(const R& input_value) : state_(new State(input_value)) {}
0970 
0971     U operator()() && { return std::move(state_->value); }
0972     U operator()() const& { return state_->value; }
0973 
0974    private:
0975     // We put our state on the heap so that the compiler-generated copy/move
0976     // constructors work correctly even when U is a reference-like type. This is
0977     // necessary only because we eagerly create State::value (see the note on
0978     // that symbol for details). If we instead had only the input value as a
0979     // member then the default constructors would work fine.
0980     //
0981     // For example, when R is std::string and U is std::string_view, value is a
0982     // reference to the string backed by input_value. The copy constructor would
0983     // copy both, so that we wind up with a new input_value object (with the
0984     // same contents) and a reference to the *old* input_value object rather
0985     // than the new one.
0986     struct State {
0987       explicit State(const R& input_value_in)
0988           : input_value(input_value_in),
0989             // Make an implicit conversion to Result before initializing the U
0990             // object we store, avoiding calling any explicit constructor of U
0991             // from R.
0992             //
0993             // This simulates the language rules: a function with return type U
0994             // that does `return R()` requires R to be implicitly convertible to
0995             // U, and uses that path for the conversion, even U Result has an
0996             // explicit constructor from R.
0997             value(ImplicitCast_<U>(internal::as_const(input_value))) {}
0998 
0999       // As above, but for the case where we're moving from the ReturnAction
1000       // object because it's being used as a OnceAction.
1001       explicit State(R&& input_value_in)
1002           : input_value(std::move(input_value_in)),
1003             // For the same reason as above we make an implicit conversion to U
1004             // before initializing the value.
1005             //
1006             // Unlike above we provide the input value as an rvalue to the
1007             // implicit conversion because this is a OnceAction: it's fine if it
1008             // wants to consume the input value.
1009             value(ImplicitCast_<U>(std::move(input_value))) {}
1010 
1011       // A copy of the value originally provided by the user. We retain this in
1012       // addition to the value of the mock function's result type below in case
1013       // the latter is a reference-like type. See the std::string_view example
1014       // in the documentation on Return.
1015       R input_value;
1016 
1017       // The value we actually return, as the type returned by the mock function
1018       // itself.
1019       //
1020       // We eagerly initialize this here, rather than lazily doing the implicit
1021       // conversion automatically each time Perform is called, for historical
1022       // reasons: in 2009-11, commit a070cbd91c (Google changelist 13540126)
1023       // made the Action<U()> conversion operator eagerly convert the R value to
1024       // U, but without keeping the R alive. This broke the use case discussed
1025       // in the documentation for Return, making reference-like types such as
1026       // std::string_view not safe to use as U where the input type R is a
1027       // value-like type such as std::string.
1028       //
1029       // The example the commit gave was not very clear, nor was the issue
1030       // thread (https://github.com/google/googlemock/issues/86), but it seems
1031       // the worry was about reference-like input types R that flatten to a
1032       // value-like type U when being implicitly converted. An example of this
1033       // is std::vector<bool>::reference, which is often a proxy type with an
1034       // reference to the underlying vector:
1035       //
1036       //     // Helper method: have the mock function return bools according
1037       //     // to the supplied script.
1038       //     void SetActions(MockFunction<bool(size_t)>& mock,
1039       //                     const std::vector<bool>& script) {
1040       //       for (size_t i = 0; i < script.size(); ++i) {
1041       //         EXPECT_CALL(mock, Call(i)).WillOnce(Return(script[i]));
1042       //       }
1043       //     }
1044       //
1045       //     TEST(Foo, Bar) {
1046       //       // Set actions using a temporary vector, whose operator[]
1047       //       // returns proxy objects that references that will be
1048       //       // dangling once the call to SetActions finishes and the
1049       //       // vector is destroyed.
1050       //       MockFunction<bool(size_t)> mock;
1051       //       SetActions(mock, {false, true});
1052       //
1053       //       EXPECT_FALSE(mock.AsStdFunction()(0));
1054       //       EXPECT_TRUE(mock.AsStdFunction()(1));
1055       //     }
1056       //
1057       // This eager conversion helps with a simple case like this, but doesn't
1058       // fully make these types work in general. For example the following still
1059       // uses a dangling reference:
1060       //
1061       //     TEST(Foo, Baz) {
1062       //       MockFunction<std::vector<std::string>()> mock;
1063       //
1064       //       // Return the same vector twice, and then the empty vector
1065       //       // thereafter.
1066       //       auto action = Return(std::initializer_list<std::string>{
1067       //           "taco", "burrito",
1068       //       });
1069       //
1070       //       EXPECT_CALL(mock, Call)
1071       //           .WillOnce(action)
1072       //           .WillOnce(action)
1073       //           .WillRepeatedly(Return(std::vector<std::string>{}));
1074       //
1075       //       EXPECT_THAT(mock.AsStdFunction()(),
1076       //                   ElementsAre("taco", "burrito"));
1077       //       EXPECT_THAT(mock.AsStdFunction()(),
1078       //                   ElementsAre("taco", "burrito"));
1079       //       EXPECT_THAT(mock.AsStdFunction()(), IsEmpty());
1080       //     }
1081       //
1082       U value;
1083     };
1084 
1085     const std::shared_ptr<State> state_;
1086   };
1087 
1088   R value_;
1089 };
1090 
1091 // A specialization of ReturnAction<R> when R is ByMoveWrapper<T> for some T.
1092 //
1093 // This version applies the type system-defeating hack of moving from T even in
1094 // the const call operator, checking at runtime that it isn't called more than
1095 // once, since the user has declared their intent to do so by using ByMove.
1096 template <typename T>
1097 class [[nodiscard]] ReturnAction<ByMoveWrapper<T>> final {
1098  public:
1099   explicit ReturnAction(ByMoveWrapper<T> wrapper)
1100       : state_(new State(std::move(wrapper.payload))) {}
1101 
1102   T operator()() const {
1103     GTEST_CHECK_(!state_->called)
1104         << "A ByMove() action must be performed at most once.";
1105 
1106     state_->called = true;
1107     return std::move(state_->value);
1108   }
1109 
1110  private:
1111   // We store our state on the heap so that we are copyable as required by
1112   // Action, despite the fact that we are stateful and T may not be copyable.
1113   struct State {
1114     explicit State(T&& value_in) : value(std::move(value_in)) {}
1115 
1116     T value;
1117     bool called = false;
1118   };
1119 
1120   const std::shared_ptr<State> state_;
1121 };
1122 
1123 // Implements the ReturnNull() action.
1124 class [[nodiscard]] ReturnNullAction {
1125  public:
1126   // Allows ReturnNull() to be used in any pointer-returning function. In C++11
1127   // this is enforced by returning nullptr, and in non-C++11 by asserting a
1128   // pointer type on compile time.
1129   template <typename Result, typename ArgumentTuple>
1130   static Result Perform(const ArgumentTuple&) {
1131     return nullptr;
1132   }
1133 };
1134 
1135 // Implements the Return() action.
1136 class [[nodiscard]] ReturnVoidAction {
1137  public:
1138   // Allows Return() to be used in any void-returning function.
1139   template <typename Result, typename ArgumentTuple>
1140   static void Perform(const ArgumentTuple&) {
1141     static_assert(std::is_void<Result>::value, "Result should be void.");
1142   }
1143 };
1144 
1145 // Implements the polymorphic ReturnRef(x) action, which can be used
1146 // in any function that returns a reference to the type of x,
1147 // regardless of the argument types.
1148 template <typename T>
1149 class [[nodiscard]] ReturnRefAction {
1150  public:
1151   // Constructs a ReturnRefAction object from the reference to be returned.
1152   explicit ReturnRefAction(T& ref) : ref_(ref) {}  // NOLINT
1153 
1154   // This template type conversion operator allows ReturnRef(x) to be
1155   // used in ANY function that returns a reference to x's type.
1156   template <typename F>
1157   operator Action<F>() const {
1158     typedef typename Function<F>::Result Result;
1159     // Asserts that the function return type is a reference.  This
1160     // catches the user error of using ReturnRef(x) when Return(x)
1161     // should be used, and generates some helpful error message.
1162     static_assert(std::is_reference<Result>::value,
1163                   "use Return instead of ReturnRef to return a value");
1164     return Action<F>(new Impl<F>(ref_));
1165   }
1166 
1167  private:
1168   // Implements the ReturnRef(x) action for a particular function type F.
1169   template <typename F>
1170   class Impl : public ActionInterface<F> {
1171    public:
1172     typedef typename Function<F>::Result Result;
1173     typedef typename Function<F>::ArgumentTuple ArgumentTuple;
1174 
1175     explicit Impl(T& ref) : ref_(ref) {}  // NOLINT
1176 
1177     Result Perform(const ArgumentTuple&) override { return ref_; }
1178 
1179    private:
1180     T& ref_;
1181   };
1182 
1183   T& ref_;
1184 };
1185 
1186 // Implements the polymorphic ReturnRefOfCopy(x) action, which can be
1187 // used in any function that returns a reference to the type of x,
1188 // regardless of the argument types.
1189 template <typename T>
1190 class [[nodiscard]] ReturnRefOfCopyAction {
1191  public:
1192   // Constructs a ReturnRefOfCopyAction object from the reference to
1193   // be returned.
1194   explicit ReturnRefOfCopyAction(const T& value) : value_(value) {}  // NOLINT
1195 
1196   // This template type conversion operator allows ReturnRefOfCopy(x) to be
1197   // used in ANY function that returns a reference to x's type.
1198   template <typename F>
1199   operator Action<F>() const {
1200     typedef typename Function<F>::Result Result;
1201     // Asserts that the function return type is a reference.  This
1202     // catches the user error of using ReturnRefOfCopy(x) when Return(x)
1203     // should be used, and generates some helpful error message.
1204     static_assert(std::is_reference<Result>::value,
1205                   "use Return instead of ReturnRefOfCopy to return a value");
1206     return Action<F>(new Impl<F>(value_));
1207   }
1208 
1209  private:
1210   // Implements the ReturnRefOfCopy(x) action for a particular function type F.
1211   template <typename F>
1212   class Impl : public ActionInterface<F> {
1213    public:
1214     typedef typename Function<F>::Result Result;
1215     typedef typename Function<F>::ArgumentTuple ArgumentTuple;
1216 
1217     explicit Impl(const T& value) : value_(value) {}  // NOLINT
1218 
1219     Result Perform(const ArgumentTuple&) override { return value_; }
1220 
1221    private:
1222     T value_;
1223   };
1224 
1225   const T value_;
1226 };
1227 
1228 // Implements the polymorphic ReturnRoundRobin(v) action, which can be
1229 // used in any function that returns the element_type of v.
1230 template <typename T>
1231 class [[nodiscard]] ReturnRoundRobinAction {
1232  public:
1233   explicit ReturnRoundRobinAction(std::vector<T> values) {
1234     GTEST_CHECK_(!values.empty())
1235         << "ReturnRoundRobin requires at least one element.";
1236     state_->values = std::move(values);
1237   }
1238 
1239   template <typename... Args>
1240   T operator()(Args&&...) const {
1241     return state_->Next();
1242   }
1243 
1244  private:
1245   struct State {
1246     T Next() {
1247       T ret_val = values[i++];
1248       if (i == values.size()) i = 0;
1249       return ret_val;
1250     }
1251 
1252     std::vector<T> values;
1253     size_t i = 0;
1254   };
1255   std::shared_ptr<State> state_ = std::make_shared<State>();
1256 };
1257 
1258 // Implements the polymorphic DoDefault() action.
1259 class [[nodiscard]] DoDefaultAction {
1260  public:
1261   // This template type conversion operator allows DoDefault() to be
1262   // used in any function.
1263   template <typename F>
1264   operator Action<F>() const {
1265     return Action<F>();
1266   }  // NOLINT
1267 };
1268 
1269 // Implements the Assign action to set a given pointer referent to a
1270 // particular value.
1271 template <typename T1, typename T2>
1272 class [[nodiscard]] AssignAction {
1273  public:
1274   AssignAction(T1* ptr, T2 value) : ptr_(ptr), value_(value) {}
1275 
1276   template <typename Result, typename ArgumentTuple>
1277   void Perform(const ArgumentTuple& /* args */) const {
1278     *ptr_ = value_;
1279   }
1280 
1281  private:
1282   T1* const ptr_;
1283   const T2 value_;
1284 };
1285 
1286 #ifndef GTEST_OS_WINDOWS_MOBILE
1287 
1288 // Implements the SetErrnoAndReturn action to simulate return from
1289 // various system calls and libc functions.
1290 template <typename T>
1291 class [[nodiscard]] SetErrnoAndReturnAction {
1292  public:
1293   SetErrnoAndReturnAction(int errno_value, T result)
1294       : errno_(errno_value), result_(result) {}
1295   template <typename Result, typename ArgumentTuple>
1296   Result Perform(const ArgumentTuple& /* args */) const {
1297     errno = errno_;
1298     return result_;
1299   }
1300 
1301  private:
1302   const int errno_;
1303   const T result_;
1304 };
1305 
1306 #endif  // !GTEST_OS_WINDOWS_MOBILE
1307 
1308 // Implements the SetArgumentPointee<N>(x) action for any function
1309 // whose N-th argument (0-based) is a pointer to x's type.
1310 template <size_t N, typename A, typename = void>
1311 struct SetArgumentPointeeAction {
1312   A value;
1313 
1314   template <typename... Args>
1315   void operator()(const Args&... args) const {
1316     *::std::get<N>(std::tie(args...)) = value;
1317   }
1318 };
1319 
1320 // Implements the Invoke(object_ptr, &Class::Method) action.
1321 template <class Class, typename MethodPtr>
1322 struct InvokeMethodAction {
1323   Class* const obj_ptr;
1324   const MethodPtr method_ptr;
1325 
1326   template <typename... Args>
1327   auto operator()(Args&&... args) const
1328       -> decltype((obj_ptr->*method_ptr)(std::forward<Args>(args)...)) {
1329     return (obj_ptr->*method_ptr)(std::forward<Args>(args)...);
1330   }
1331 };
1332 
1333 // Implements the InvokeWithoutArgs(object_ptr, &Class::Method) action.
1334 template <class Class, typename MethodPtr>
1335 struct InvokeMethodWithoutArgsAction {
1336   Class* const obj_ptr;
1337   const MethodPtr method_ptr;
1338 
1339   using ReturnType =
1340       decltype((std::declval<Class*>()->*std::declval<MethodPtr>())());
1341 
1342   template <typename... Args>
1343   ReturnType operator()(const Args&...) const {
1344     return (obj_ptr->*method_ptr)();
1345   }
1346 };
1347 
1348 // Implements the IgnoreResult(action) action.
1349 template <typename A>
1350 class IgnoreResultAction {
1351  public:
1352   explicit IgnoreResultAction(const A& action) : action_(action) {}
1353 
1354   template <typename F>
1355   operator Action<F>() const {
1356     // Assert statement belongs here because this is the best place to verify
1357     // conditions on F. It produces the clearest error messages
1358     // in most compilers.
1359     // Impl really belongs in this scope as a local class but can't
1360     // because MSVC produces duplicate symbols in different translation units
1361     // in this case. Until MS fixes that bug we put Impl into the class scope
1362     // and put the typedef both here (for use in assert statement) and
1363     // in the Impl class. But both definitions must be the same.
1364     typedef typename internal::Function<F>::Result Result;
1365 
1366     // Asserts at compile time that F returns void.
1367     static_assert(std::is_void<Result>::value, "Result type should be void.");
1368 
1369     return Action<F>(new Impl<F>(action_));
1370   }
1371 
1372  private:
1373   template <typename F>
1374   class Impl : public ActionInterface<F> {
1375    public:
1376     typedef typename internal::Function<F>::Result Result;
1377     typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
1378 
1379     explicit Impl(const A& action) : action_(action) {}
1380 
1381     void Perform(const ArgumentTuple& args) override {
1382       // Performs the action and ignores its result.
1383       (void)action_.Perform(args);
1384     }
1385 
1386    private:
1387     // Type OriginalFunction is the same as F except that its return
1388     // type is IgnoredValue.
1389     typedef
1390         typename internal::Function<F>::MakeResultIgnoredValue OriginalFunction;
1391 
1392     const Action<OriginalFunction> action_;
1393   };
1394 
1395   const A action_;
1396 };
1397 
1398 template <typename InnerAction, size_t... I>
1399 struct WithArgsAction {
1400   InnerAction inner_action;
1401 
1402   // The signature of the function as seen by the inner action, given an out
1403   // action with the given result and argument types.
1404   template <typename R, typename... Args>
1405   using InnerSignature =
1406       R(typename std::tuple_element<I, std::tuple<Args...>>::type...);
1407 
1408   // Rather than a call operator, we must define conversion operators to
1409   // particular action types. This is necessary for embedded actions like
1410   // DoDefault(), which rely on an action conversion operators rather than
1411   // providing a call operator because even with a particular set of arguments
1412   // they don't have a fixed return type.
1413 
1414   template <
1415       typename R, typename... Args,
1416       typename std::enable_if<
1417           std::is_convertible<InnerAction,
1418                               // Unfortunately we can't use the InnerSignature
1419                               // alias here; MSVC complains about the I
1420                               // parameter pack not being expanded (error C3520)
1421                               // despite it being expanded in the type alias.
1422                               // TupleElement is also an MSVC workaround.
1423                               // See its definition for details.
1424                               OnceAction<R(internal::TupleElement<
1425                                            I, std::tuple<Args...>>...)>>::value,
1426           int>::type = 0>
1427   operator OnceAction<R(Args...)>() && {  // NOLINT
1428     struct OA {
1429       OnceAction<InnerSignature<R, Args...>> inner_action;
1430 
1431       R operator()(Args&&... args) && {
1432         return std::move(inner_action)
1433             .Call(std::get<I>(
1434                 std::forward_as_tuple(std::forward<Args>(args)...))...);
1435       }
1436     };
1437 
1438     return OA{std::move(inner_action)};
1439   }
1440 
1441   // As above, but in the case where we want to create a OnceAction from a const
1442   // WithArgsAction. This is fine as long as the inner action doesn't need to
1443   // move any of its state to create a OnceAction.
1444   template <
1445       typename R, typename... Args,
1446       typename std::enable_if<
1447           std::is_convertible<const InnerAction&,
1448                               OnceAction<R(internal::TupleElement<
1449                                            I, std::tuple<Args...>>...)>>::value,
1450           int>::type = 0>
1451   operator OnceAction<R(Args...)>() const& {  // NOLINT
1452     struct OA {
1453       OnceAction<InnerSignature<R, Args...>> inner_action;
1454 
1455       R operator()(Args&&... args) && {
1456         return std::move(inner_action)
1457             .Call(std::get<I>(
1458                 std::forward_as_tuple(std::forward<Args>(args)...))...);
1459       }
1460     };
1461 
1462     return OA{inner_action};
1463   }
1464 
1465   template <
1466       typename R, typename... Args,
1467       typename std::enable_if<
1468           std::is_convertible<const InnerAction&,
1469                               // Unfortunately we can't use the InnerSignature
1470                               // alias here; MSVC complains about the I
1471                               // parameter pack not being expanded (error C3520)
1472                               // despite it being expanded in the type alias.
1473                               // TupleElement is also an MSVC workaround.
1474                               // See its definition for details.
1475                               Action<R(internal::TupleElement<
1476                                        I, std::tuple<Args...>>...)>>::value,
1477           int>::type = 0>
1478   operator Action<R(Args...)>() const {  // NOLINT
1479     Action<InnerSignature<R, Args...>> converted(inner_action);
1480 
1481     return [converted](Args&&... args) -> R {
1482       return converted.Perform(std::forward_as_tuple(
1483           std::get<I>(std::forward_as_tuple(std::forward<Args>(args)...))...));
1484     };
1485   }
1486 };
1487 
1488 template <typename... Actions>
1489 class [[nodiscard]] DoAllAction;
1490 
1491 // Base case: only a single action.
1492 template <typename FinalAction>
1493 class [[nodiscard]] DoAllAction<FinalAction> {
1494  public:
1495   struct UserConstructorTag {};
1496 
1497   template <typename T>
1498   explicit DoAllAction(UserConstructorTag, T&& action)
1499       : final_action_(std::forward<T>(action)) {}
1500 
1501   // Rather than a call operator, we must define conversion operators to
1502   // particular action types. This is necessary for embedded actions like
1503   // DoDefault(), which rely on an action conversion operators rather than
1504   // providing a call operator because even with a particular set of arguments
1505   // they don't have a fixed return type.
1506 
1507   // We support conversion to OnceAction whenever the sub-action does.
1508   template <typename R, typename... Args,
1509             typename std::enable_if<
1510                 std::is_convertible<FinalAction, OnceAction<R(Args...)>>::value,
1511                 int>::type = 0>
1512   operator OnceAction<R(Args...)>() && {  // NOLINT
1513     return std::move(final_action_);
1514   }
1515 
1516   // We also support conversion to OnceAction whenever the sub-action supports
1517   // conversion to Action (since any Action can also be a OnceAction).
1518   template <
1519       typename R, typename... Args,
1520       typename std::enable_if<
1521           conjunction<
1522               negation<
1523                   std::is_convertible<FinalAction, OnceAction<R(Args...)>>>,
1524               std::is_convertible<FinalAction, Action<R(Args...)>>>::value,
1525           int>::type = 0>
1526   operator OnceAction<R(Args...)>() && {  // NOLINT
1527     return Action<R(Args...)>(std::move(final_action_));
1528   }
1529 
1530   // We support conversion to Action whenever the sub-action does.
1531   template <
1532       typename R, typename... Args,
1533       typename std::enable_if<
1534           std::is_convertible<const FinalAction&, Action<R(Args...)>>::value,
1535           int>::type = 0>
1536   operator Action<R(Args...)>() const {  // NOLINT
1537     return final_action_;
1538   }
1539 
1540  private:
1541   FinalAction final_action_;
1542 };
1543 
1544 // Recursive case: support N actions by calling the initial action and then
1545 // calling through to the base class containing N-1 actions.
1546 template <typename InitialAction, typename... OtherActions>
1547 class [[nodiscard]] DoAllAction<InitialAction, OtherActions...>
1548     : private DoAllAction<OtherActions...> {
1549  private:
1550   using Base = DoAllAction<OtherActions...>;
1551 
1552   // The type of reference that should be provided to an initial action for a
1553   // mocked function parameter of type T.
1554   //
1555   // There are two quirks here:
1556   //
1557   //  *  Unlike most forwarding functions, we pass scalars through by value.
1558   //     This isn't strictly necessary because an lvalue reference would work
1559   //     fine too and be consistent with other non-reference types, but it's
1560   //     perhaps less surprising.
1561   //
1562   //     For example if the mocked function has signature void(int), then it
1563   //     might seem surprising for the user's initial action to need to be
1564   //     convertible to Action<void(const int&)>. This is perhaps less
1565   //     surprising for a non-scalar type where there may be a performance
1566   //     impact, or it might even be impossible, to pass by value.
1567   //
1568   //  *  More surprisingly, `const T&` is often not a const reference type.
1569   //     By the reference collapsing rules in C++17 [dcl.ref]/6, if T refers to
1570   //     U& or U&& for some non-scalar type U, then InitialActionArgType<T> is
1571   //     U&. In other words, we may hand over a non-const reference.
1572   //
1573   //     So for example, given some non-scalar type Obj we have the following
1574   //     mappings:
1575   //
1576   //            T               InitialActionArgType<T>
1577   //         -------            -----------------------
1578   //         Obj                const Obj&
1579   //         Obj&               Obj&
1580   //         Obj&&              Obj&
1581   //         const Obj          const Obj&
1582   //         const Obj&         const Obj&
1583   //         const Obj&&        const Obj&
1584   //
1585   //     In other words, the initial actions get a mutable view of an non-scalar
1586   //     argument if and only if the mock function itself accepts a non-const
1587   //     reference type. They are never given an rvalue reference to an
1588   //     non-scalar type.
1589   //
1590   //     This situation makes sense if you imagine use with a matcher that is
1591   //     designed to write through a reference. For example, if the caller wants
1592   //     to fill in a reference argument and then return a canned value:
1593   //
1594   //         EXPECT_CALL(mock, Call)
1595   //             .WillOnce(DoAll(SetArgReferee<0>(17), Return(19)));
1596   //
1597   template <typename T>
1598   using InitialActionArgType =
1599       typename std::conditional<std::is_scalar<T>::value, T, const T&>::type;
1600 
1601  public:
1602   struct UserConstructorTag {};
1603 
1604   template <typename T, typename... U>
1605   explicit DoAllAction(UserConstructorTag, T&& initial_action,
1606                        U&&... other_actions)
1607       : Base({}, std::forward<U>(other_actions)...),
1608         initial_action_(std::forward<T>(initial_action)) {}
1609 
1610   // We support conversion to OnceAction whenever both the initial action and
1611   // the rest support conversion to OnceAction.
1612   template <
1613       typename R, typename... Args,
1614       typename std::enable_if<
1615           conjunction<std::is_convertible<
1616                           InitialAction,
1617                           OnceAction<void(InitialActionArgType<Args>...)>>,
1618                       std::is_convertible<Base, OnceAction<R(Args...)>>>::value,
1619           int>::type = 0>
1620   operator OnceAction<R(Args...)>() && {  // NOLINT
1621     // Return an action that first calls the initial action with arguments
1622     // filtered through InitialActionArgType, then forwards arguments directly
1623     // to the base class to deal with the remaining actions.
1624     struct OA {
1625       OnceAction<void(InitialActionArgType<Args>...)> initial_action;
1626       OnceAction<R(Args...)> remaining_actions;
1627 
1628       R operator()(Args... args) && {
1629         std::move(initial_action)
1630             .Call(static_cast<InitialActionArgType<Args>>(args)...);
1631 
1632         return std::move(remaining_actions).Call(std::forward<Args>(args)...);
1633       }
1634     };
1635 
1636     return OA{
1637         std::move(initial_action_),
1638         std::move(static_cast<Base&>(*this)),
1639     };
1640   }
1641 
1642   // We also support conversion to OnceAction whenever the initial action
1643   // supports conversion to Action (since any Action can also be a OnceAction).
1644   //
1645   // The remaining sub-actions must also be compatible, but we don't need to
1646   // special case them because the base class deals with them.
1647   template <
1648       typename R, typename... Args,
1649       typename std::enable_if<
1650           conjunction<
1651               negation<std::is_convertible<
1652                   InitialAction,
1653                   OnceAction<void(InitialActionArgType<Args>...)>>>,
1654               std::is_convertible<InitialAction,
1655                                   Action<void(InitialActionArgType<Args>...)>>,
1656               std::is_convertible<Base, OnceAction<R(Args...)>>>::value,
1657           int>::type = 0>
1658   operator OnceAction<R(Args...)>() && {  // NOLINT
1659     return DoAll(
1660         Action<void(InitialActionArgType<Args>...)>(std::move(initial_action_)),
1661         std::move(static_cast<Base&>(*this)));
1662   }
1663 
1664   // We support conversion to Action whenever both the initial action and the
1665   // rest support conversion to Action.
1666   template <
1667       typename R, typename... Args,
1668       typename std::enable_if<
1669           conjunction<
1670               std::is_convertible<const InitialAction&,
1671                                   Action<void(InitialActionArgType<Args>...)>>,
1672               std::is_convertible<const Base&, Action<R(Args...)>>>::value,
1673           int>::type = 0>
1674   operator Action<R(Args...)>() const {  // NOLINT
1675     // Return an action that first calls the initial action with arguments
1676     // filtered through InitialActionArgType, then forwards arguments directly
1677     // to the base class to deal with the remaining actions.
1678     struct OA {
1679       Action<void(InitialActionArgType<Args>...)> initial_action;
1680       Action<R(Args...)> remaining_actions;
1681 
1682       R operator()(Args... args) const {
1683         initial_action.Perform(std::forward_as_tuple(
1684             static_cast<InitialActionArgType<Args>>(args)...));
1685 
1686         return remaining_actions.Perform(
1687             std::forward_as_tuple(std::forward<Args>(args)...));
1688       }
1689     };
1690 
1691     return OA{
1692         initial_action_,
1693         static_cast<const Base&>(*this),
1694     };
1695   }
1696 
1697  private:
1698   InitialAction initial_action_;
1699 };
1700 
1701 template <typename T, typename... Params>
1702 struct ReturnNewAction {
1703   T* operator()() const {
1704     return internal::Apply(
1705         [](const Params&... unpacked_params) {
1706           return new T(unpacked_params...);
1707         },
1708         params);
1709   }
1710   std::tuple<Params...> params;
1711 };
1712 
1713 template <size_t k>
1714 struct ReturnArgAction {
1715   template <typename... Args,
1716             typename = typename std::enable_if<(k < sizeof...(Args))>::type>
1717   auto operator()(Args&&... args) const -> decltype(std::get<k>(
1718       std::forward_as_tuple(std::forward<Args>(args)...))) {
1719     return std::get<k>(std::forward_as_tuple(std::forward<Args>(args)...));
1720   }
1721 };
1722 
1723 template <size_t k, typename Ptr>
1724 struct SaveArgAction {
1725   Ptr pointer;
1726 
1727   template <typename... Args>
1728   void operator()(const Args&... args) const {
1729     *pointer = std::get<k>(std::tie(args...));
1730   }
1731 };
1732 
1733 template <size_t k, typename Ptr>
1734 struct SaveArgByMoveAction {
1735   Ptr pointer;
1736 
1737   template <typename... Args>
1738   void operator()(Args&&... args) const {
1739     *pointer = std::move(std::get<k>(std::tie(args...)));
1740   }
1741 };
1742 
1743 template <size_t k, typename Ptr>
1744 struct SaveArgPointeeAction {
1745   Ptr pointer;
1746 
1747   template <typename... Args>
1748   void operator()(const Args&... args) const {
1749     *pointer = *std::get<k>(std::tie(args...));
1750   }
1751 };
1752 
1753 template <size_t k, typename T>
1754 struct SetArgRefereeAction {
1755   T value;
1756 
1757   template <typename... Args>
1758   void operator()(Args&&... args) const {
1759     using argk_type =
1760         typename ::std::tuple_element<k, std::tuple<Args...>>::type;
1761     static_assert(std::is_lvalue_reference<argk_type>::value,
1762                   "Argument must be a reference type.");
1763     std::get<k>(std::tie(args...)) = value;
1764   }
1765 };
1766 
1767 template <size_t k, typename I1, typename I2>
1768 struct SetArrayArgumentAction {
1769   I1 first;
1770   I2 last;
1771 
1772   template <typename... Args>
1773   void operator()(const Args&... args) const {
1774     auto value = std::get<k>(std::tie(args...));
1775     for (auto it = first; it != last; ++it, (void)++value) {
1776       *value = *it;
1777     }
1778   }
1779 };
1780 
1781 template <size_t k>
1782 class [[nodiscard]] DeleteArgAction {
1783  public:
1784   template <typename... Args>
1785   void operator()(const Args&... args) const {
1786     DoDelete(std::get<k>(std::tie(args...)));
1787   }
1788 
1789  private:
1790   template <typename T>
1791   static void DoDelete(T* ptr) {
1792     delete ptr;
1793   }
1794 
1795   template <typename T>
1796   [[deprecated(
1797       "DeleteArg<N> used for a non-pointer argument, it was likely migrated "
1798       "to a smart pointer type. This action should be removed.")]]
1799   static void DoDelete(T&) {}
1800 };
1801 
1802 template <typename Ptr>
1803 struct ReturnPointeeAction {
1804   Ptr pointer;
1805   template <typename... Args>
1806   auto operator()(const Args&...) const -> decltype(*pointer) {
1807     return *pointer;
1808   }
1809 };
1810 
1811 #if GTEST_HAS_EXCEPTIONS
1812 template <typename T>
1813 struct ThrowAction {
1814   T exception;
1815   // We use a conversion operator to adapt to any return type.
1816   template <typename R, typename... Args>
1817   operator Action<R(Args...)>() const {  // NOLINT
1818     T copy = exception;
1819     return [copy](Args...) -> R { throw copy; };
1820   }
1821 };
1822 struct RethrowAction {
1823   std::exception_ptr exception;
1824   template <typename R, typename... Args>
1825   operator Action<R(Args...)>() const {  // NOLINT
1826     return [ex = exception](Args...) -> R { std::rethrow_exception(ex); };
1827   }
1828 };
1829 #endif  // GTEST_HAS_EXCEPTIONS
1830 
1831 }  // namespace internal
1832 
1833 // An Unused object can be implicitly constructed from ANY value.
1834 // This is handy when defining actions that ignore some or all of the
1835 // mock function arguments.  For example, given
1836 //
1837 //   MOCK_METHOD3(Foo, double(const string& label, double x, double y));
1838 //   MOCK_METHOD3(Bar, double(int index, double x, double y));
1839 //
1840 // instead of
1841 //
1842 //   double DistanceToOriginWithLabel(const string& label, double x, double y) {
1843 //     return sqrt(x*x + y*y);
1844 //   }
1845 //   double DistanceToOriginWithIndex(int index, double x, double y) {
1846 //     return sqrt(x*x + y*y);
1847 //   }
1848 //   ...
1849 //   EXPECT_CALL(mock, Foo("abc", _, _))
1850 //       .WillOnce(Invoke(DistanceToOriginWithLabel));
1851 //   EXPECT_CALL(mock, Bar(5, _, _))
1852 //       .WillOnce(Invoke(DistanceToOriginWithIndex));
1853 //
1854 // you could write
1855 //
1856 //   // We can declare any uninteresting argument as Unused.
1857 //   double DistanceToOrigin(Unused, double x, double y) {
1858 //     return sqrt(x*x + y*y);
1859 //   }
1860 //   ...
1861 //   EXPECT_CALL(mock, Foo("abc", _, _)).WillOnce(Invoke(DistanceToOrigin));
1862 //   EXPECT_CALL(mock, Bar(5, _, _)).WillOnce(Invoke(DistanceToOrigin));
1863 typedef internal::IgnoredValue Unused;
1864 
1865 // Deprecated single-argument DoAll.
1866 template <typename Action>
1867 GTEST_INTERNAL_DEPRECATE_AND_INLINE("Avoid using DoAll() for single actions")
1868 typename std::decay<Action>::type DoAll(Action&& action) {
1869   return std::forward<Action>(action);
1870 }
1871 
1872 // Creates an action that does actions a1, a2, ..., sequentially in
1873 // each invocation. All but the last action will have a readonly view of the
1874 // arguments.
1875 template <typename... Action>
1876 internal::DoAllAction<typename std::decay<Action>::type...> DoAll(
1877     Action&&... action) {
1878   return internal::DoAllAction<typename std::decay<Action>::type...>(
1879       {}, std::forward<Action>(action)...);
1880 }
1881 
1882 // WithArg<k>(an_action) creates an action that passes the k-th
1883 // (0-based) argument of the mock function to an_action and performs
1884 // it.  It adapts an action accepting one argument to one that accepts
1885 // multiple arguments.  For convenience, we also provide
1886 // WithArgs<k>(an_action) (defined below) as a synonym.
1887 template <size_t k, typename InnerAction>
1888 internal::WithArgsAction<typename std::decay<InnerAction>::type, k> WithArg(
1889     InnerAction&& action) {
1890   return {std::forward<InnerAction>(action)};
1891 }
1892 
1893 // WithArgs<N1, N2, ..., Nk>(an_action) creates an action that passes
1894 // the selected arguments of the mock function to an_action and
1895 // performs it.  It serves as an adaptor between actions with
1896 // different argument lists.
1897 template <size_t k, size_t... ks, typename InnerAction>
1898 internal::WithArgsAction<typename std::decay<InnerAction>::type, k, ks...>
1899 WithArgs(InnerAction&& action) {
1900   return {std::forward<InnerAction>(action)};
1901 }
1902 
1903 // WithoutArgs(inner_action) can be used in a mock function with a
1904 // non-empty argument list to perform inner_action, which takes no
1905 // argument.  In other words, it adapts an action accepting no
1906 // argument to one that accepts (and ignores) arguments.
1907 template <typename InnerAction>
1908 internal::WithArgsAction<typename std::decay<InnerAction>::type> WithoutArgs(
1909     InnerAction&& action) {
1910   return {std::forward<InnerAction>(action)};
1911 }
1912 
1913 // Creates an action that returns a value.
1914 //
1915 // The returned type can be used with a mock function returning a non-void,
1916 // non-reference type U as follows:
1917 //
1918 //  *  If R is convertible to U and U is move-constructible, then the action can
1919 //     be used with WillOnce.
1920 //
1921 //  *  If const R& is convertible to U and U is copy-constructible, then the
1922 //     action can be used with both WillOnce and WillRepeatedly.
1923 //
1924 // The mock expectation contains the R value from which the U return value is
1925 // constructed (a move/copy of the argument to Return). This means that the R
1926 // value will survive at least until the mock object's expectations are cleared
1927 // or the mock object is destroyed, meaning that U can safely be a
1928 // reference-like type such as std::string_view:
1929 //
1930 //     // The mock function returns a view of a copy of the string fed to
1931 //     // Return. The view is valid even after the action is performed.
1932 //     MockFunction<std::string_view()> mock;
1933 //     EXPECT_CALL(mock, Call).WillOnce(Return(std::string("taco")));
1934 //     const std::string_view result = mock.AsStdFunction()();
1935 //     EXPECT_EQ("taco", result);
1936 //
1937 template <typename R>
1938 internal::ReturnAction<R> Return(R value) {
1939   return internal::ReturnAction<R>(std::move(value));
1940 }
1941 
1942 // Creates an action that returns NULL.
1943 inline PolymorphicAction<internal::ReturnNullAction> ReturnNull() {
1944   return MakePolymorphicAction(internal::ReturnNullAction());
1945 }
1946 
1947 // Creates an action that returns from a void function.
1948 inline PolymorphicAction<internal::ReturnVoidAction> Return() {
1949   return MakePolymorphicAction(internal::ReturnVoidAction());
1950 }
1951 
1952 // Creates an action that returns the reference to a variable.
1953 template <typename R>
1954 inline internal::ReturnRefAction<R> ReturnRef(R& x) {  // NOLINT
1955   return internal::ReturnRefAction<R>(x);
1956 }
1957 
1958 // Prevent using ReturnRef on reference to temporary.
1959 template <typename R, R* = nullptr>
1960 internal::ReturnRefAction<R> ReturnRef(R&&) = delete;
1961 
1962 // Creates an action that returns the reference to a copy of the
1963 // argument.  The copy is created when the action is constructed and
1964 // lives as long as the action.
1965 template <typename R>
1966 inline internal::ReturnRefOfCopyAction<R> ReturnRefOfCopy(const R& x) {
1967   return internal::ReturnRefOfCopyAction<R>(x);
1968 }
1969 
1970 // DEPRECATED: use Return(x) directly with WillOnce.
1971 //
1972 // Modifies the parent action (a Return() action) to perform a move of the
1973 // argument instead of a copy.
1974 // Return(ByMove()) actions can only be executed once and will assert this
1975 // invariant.
1976 template <typename R>
1977 internal::ByMoveWrapper<R> ByMove(R x) {
1978   return internal::ByMoveWrapper<R>(std::move(x));
1979 }
1980 
1981 // Creates an action that returns an element of `vals`. Calling this action will
1982 // repeatedly return the next value from `vals` until it reaches the end and
1983 // will restart from the beginning.
1984 template <typename T>
1985 internal::ReturnRoundRobinAction<T> ReturnRoundRobin(std::vector<T> vals) {
1986   return internal::ReturnRoundRobinAction<T>(std::move(vals));
1987 }
1988 
1989 // Creates an action that returns an element of `vals`. Calling this action will
1990 // repeatedly return the next value from `vals` until it reaches the end and
1991 // will restart from the beginning.
1992 template <typename T>
1993 internal::ReturnRoundRobinAction<T> ReturnRoundRobin(
1994     std::initializer_list<T> vals) {
1995   return internal::ReturnRoundRobinAction<T>(std::vector<T>(vals));
1996 }
1997 
1998 // Creates an action that does the default action for the give mock function.
1999 inline internal::DoDefaultAction DoDefault() {
2000   return internal::DoDefaultAction();
2001 }
2002 
2003 // Creates an action that sets the variable pointed by the N-th
2004 // (0-based) function argument to 'value'.
2005 template <size_t N, typename T>
2006 internal::SetArgumentPointeeAction<N, T> SetArgPointee(T value) {
2007   return {std::move(value)};
2008 }
2009 
2010 // The following version is DEPRECATED.
2011 template <size_t N, typename T>
2012 internal::SetArgumentPointeeAction<N, T> SetArgumentPointee(T value) {
2013   return {std::move(value)};
2014 }
2015 
2016 // Creates an action that sets a pointer referent to a given value.
2017 template <typename T1, typename T2>
2018 PolymorphicAction<internal::AssignAction<T1, T2>> Assign(T1* ptr, T2 val) {
2019   return MakePolymorphicAction(internal::AssignAction<T1, T2>(ptr, val));
2020 }
2021 
2022 #ifndef GTEST_OS_WINDOWS_MOBILE
2023 
2024 // Creates an action that sets errno and returns the appropriate error.
2025 template <typename T>
2026 PolymorphicAction<internal::SetErrnoAndReturnAction<T>> SetErrnoAndReturn(
2027     int errval, T result) {
2028   return MakePolymorphicAction(
2029       internal::SetErrnoAndReturnAction<T>(errval, result));
2030 }
2031 
2032 #endif  // !GTEST_OS_WINDOWS_MOBILE
2033 
2034 // Various overloads for Invoke().
2035 
2036 // Legacy function.
2037 // This function exists for backwards compatibility.
2038 template <typename FunctionImpl>
2039 GTEST_INTERNAL_DEPRECATE_AND_INLINE(
2040     "Actions can now be implicitly constructed from callables. No need to "
2041     "create wrapper objects using Invoke().")
2042 typename std::decay<FunctionImpl>::type Invoke(FunctionImpl&& function_impl) {
2043   return std::forward<FunctionImpl>(function_impl);
2044 }
2045 
2046 // Creates an action that invokes the given method on the given object
2047 // with the mock function's arguments.
2048 template <class Class, typename MethodPtr>
2049 internal::InvokeMethodAction<Class, MethodPtr> Invoke(Class* obj_ptr,
2050                                                       MethodPtr method_ptr) {
2051   return {obj_ptr, method_ptr};
2052 }
2053 
2054 // Creates an action that invokes 'function_impl' with no argument.
2055 template <typename FunctionImpl>
2056 GTEST_INTERNAL_DEPRECATE_AND_INLINE(
2057     "Actions can now be implicitly constructed from zero-argument callables. "
2058     "No need to create wrapper objects using InvokeWithoutArgs().")
2059 std::decay_t<FunctionImpl> InvokeWithoutArgs(FunctionImpl&& function_impl) {
2060   return std::forward<FunctionImpl>(function_impl);
2061 }
2062 
2063 // Creates an action that invokes the given method on the given object
2064 // with no argument.
2065 template <class Class, typename MethodPtr>
2066 internal::InvokeMethodWithoutArgsAction<Class, MethodPtr> InvokeWithoutArgs(
2067     Class* obj_ptr, MethodPtr method_ptr) {
2068   return {obj_ptr, method_ptr};
2069 }
2070 
2071 // Creates an action that performs an_action and throws away its
2072 // result.  In other words, it changes the return type of an_action to
2073 // void.  an_action MUST NOT return void, or the code won't compile.
2074 template <typename A>
2075 inline internal::IgnoreResultAction<A> IgnoreResult(const A& an_action) {
2076   return internal::IgnoreResultAction<A>(an_action);
2077 }
2078 
2079 // Creates a reference wrapper for the given L-value.  If necessary,
2080 // you can explicitly specify the type of the reference.  For example,
2081 // suppose 'derived' is an object of type Derived, ByRef(derived)
2082 // would wrap a Derived&.  If you want to wrap a const Base& instead,
2083 // where Base is a base class of Derived, just write:
2084 //
2085 //   ByRef<const Base>(derived)
2086 //
2087 // N.B. ByRef is redundant with std::ref, std::cref and std::reference_wrapper.
2088 // However, it may still be used for consistency with ByMove().
2089 template <typename T>
2090 inline ::std::reference_wrapper<T> ByRef(T& l_value) {  // NOLINT
2091   return ::std::reference_wrapper<T>(l_value);
2092 }
2093 
2094 // The ReturnNew<T>(a1, a2, ..., a_k) action returns a pointer to a new
2095 // instance of type T, constructed on the heap with constructor arguments
2096 // a1, a2, ..., and a_k. The caller assumes ownership of the returned value.
2097 template <typename T, typename... Params>
2098 internal::ReturnNewAction<T, typename std::decay<Params>::type...> ReturnNew(
2099     Params&&... params) {
2100   return {std::forward_as_tuple(std::forward<Params>(params)...)};
2101 }
2102 
2103 // Action ReturnArg<k>() returns the k-th argument of the mock function.
2104 template <size_t k>
2105 internal::ReturnArgAction<k> ReturnArg() {
2106   return {};
2107 }
2108 
2109 // Action SaveArg<k>(pointer) saves the k-th (0-based) argument of the
2110 // mock function to *pointer.
2111 template <size_t k, typename Ptr>
2112 internal::SaveArgAction<k, Ptr> SaveArg(Ptr pointer) {
2113   return {pointer};
2114 }
2115 
2116 // Action SaveArgByMove<k>(pointer) moves the k-th (0-based) argument of the
2117 // mock function into *pointer.
2118 template <size_t k, typename Ptr>
2119 internal::SaveArgByMoveAction<k, Ptr> SaveArgByMove(Ptr pointer) {
2120   return {pointer};
2121 }
2122 
2123 // Action SaveArgPointee<k>(pointer) saves the value pointed to
2124 // by the k-th (0-based) argument of the mock function to *pointer.
2125 template <size_t k, typename Ptr>
2126 internal::SaveArgPointeeAction<k, Ptr> SaveArgPointee(Ptr pointer) {
2127   return {pointer};
2128 }
2129 
2130 // Action SetArgReferee<k>(value) assigns 'value' to the variable
2131 // referenced by the k-th (0-based) argument of the mock function.
2132 template <size_t k, typename T>
2133 internal::SetArgRefereeAction<k, typename std::decay<T>::type> SetArgReferee(
2134     T&& value) {
2135   return {std::forward<T>(value)};
2136 }
2137 
2138 // Action SetArrayArgument<k>(first, last) copies the elements in
2139 // source range [first, last) to the array pointed to by the k-th
2140 // (0-based) argument, which can be either a pointer or an
2141 // iterator. The action does not take ownership of the elements in the
2142 // source range.
2143 template <size_t k, typename I1, typename I2>
2144 internal::SetArrayArgumentAction<k, I1, I2> SetArrayArgument(I1 first,
2145                                                              I2 last) {
2146   return {first, last};
2147 }
2148 
2149 // Action DeleteArg<k>() deletes the k-th (0-based) argument of the mock
2150 // function.
2151 template <size_t k>
2152 internal::DeleteArgAction<k> DeleteArg() {
2153   return {};
2154 }
2155 
2156 // This action returns the value pointed to by 'pointer'.
2157 template <typename Ptr>
2158 internal::ReturnPointeeAction<Ptr> ReturnPointee(Ptr pointer) {
2159   return {pointer};
2160 }
2161 
2162 #if GTEST_HAS_EXCEPTIONS
2163 // Action Throw(exception) can be used in a mock function of any type
2164 // to throw the given exception.  Any copyable value can be thrown,
2165 // except for std::exception_ptr, which is likely a mistake if
2166 // thrown directly.
2167 template <typename T>
2168 typename std::enable_if<
2169     !std::is_base_of<std::exception_ptr, typename std::decay<T>::type>::value,
2170     internal::ThrowAction<typename std::decay<T>::type>>::type
2171 Throw(T&& exception) {
2172   return {std::forward<T>(exception)};
2173 }
2174 // Action Rethrow(exception_ptr) can be used in a mock function of any type
2175 // to rethrow any exception_ptr. Note that the same object is thrown each time.
2176 inline internal::RethrowAction Rethrow(std::exception_ptr exception) {
2177   return {std::move(exception)};
2178 }
2179 #endif  // GTEST_HAS_EXCEPTIONS
2180 
2181 namespace internal {
2182 
2183 // A macro from the ACTION* family (defined later in gmock-generated-actions.h)
2184 // defines an action that can be used in a mock function.  Typically,
2185 // these actions only care about a subset of the arguments of the mock
2186 // function.  For example, if such an action only uses the second
2187 // argument, it can be used in any mock function that takes >= 2
2188 // arguments where the type of the second argument is compatible.
2189 //
2190 // Therefore, the action implementation must be prepared to take more
2191 // arguments than it needs.  The ExcessiveArg type is used to
2192 // represent those excessive arguments.  In order to keep the compiler
2193 // error messages tractable, we define it in the testing namespace
2194 // instead of testing::internal.  However, this is an INTERNAL TYPE
2195 // and subject to change without notice, so a user MUST NOT USE THIS
2196 // TYPE DIRECTLY.
2197 struct ExcessiveArg {};
2198 
2199 // Builds an implementation of an Action<> for some particular signature, using
2200 // a class defined by an ACTION* macro.
2201 template <typename F, typename Impl>
2202 struct ActionImpl;
2203 
2204 template <typename Impl>
2205 struct ImplBase {
2206   struct Holder {
2207     // Allows each copy of the Action<> to get to the Impl.
2208     explicit operator const Impl&() const { return *ptr; }
2209     std::shared_ptr<Impl> ptr;
2210   };
2211   using type = typename std::conditional<std::is_constructible<Impl>::value,
2212                                          Impl, Holder>::type;
2213 };
2214 
2215 template <typename R, typename... Args, typename Impl>
2216 struct ActionImpl<R(Args...), Impl> : ImplBase<Impl>::type {
2217   using Base = typename ImplBase<Impl>::type;
2218   using function_type = R(Args...);
2219   using args_type = std::tuple<Args...>;
2220 
2221   ActionImpl() = default;  // Only defined if appropriate for Base.
2222   explicit ActionImpl(std::shared_ptr<Impl> impl) : Base{std::move(impl)} {}
2223 
2224   R operator()(Args&&... arg) const {
2225     static constexpr size_t kMaxArgs =
2226         sizeof...(Args) <= 10 ? sizeof...(Args) : 10;
2227     return Apply(std::make_index_sequence<kMaxArgs>{},
2228                  std::make_index_sequence<10 - kMaxArgs>{},
2229                  args_type{std::forward<Args>(arg)...});
2230   }
2231 
2232   template <std::size_t... arg_id, std::size_t... excess_id>
2233   R Apply(std::index_sequence<arg_id...>, std::index_sequence<excess_id...>,
2234           const args_type& args) const {
2235     // Impl need not be specific to the signature of action being implemented;
2236     // only the implementing function body needs to have all of the specific
2237     // types instantiated.  Up to 10 of the args that are provided by the
2238     // args_type get passed, followed by a dummy of unspecified type for the
2239     // remainder up to 10 explicit args.
2240     static constexpr ExcessiveArg kExcessArg{};
2241     return static_cast<const Impl&>(*this)
2242         .template gmock_PerformImpl<
2243             /*function_type=*/function_type, /*return_type=*/R,
2244             /*args_type=*/args_type,
2245             /*argN_type=*/
2246             typename std::tuple_element<arg_id, args_type>::type...>(
2247             /*args=*/args, std::get<arg_id>(args)...,
2248             ((void)excess_id, kExcessArg)...);
2249   }
2250 };
2251 
2252 // Stores a default-constructed Impl as part of the Action<>'s
2253 // std::function<>. The Impl should be trivial to copy.
2254 template <typename F, typename Impl>
2255 ::testing::Action<F> MakeAction() {
2256   return ::testing::Action<F>(ActionImpl<F, Impl>());
2257 }
2258 
2259 // Stores just the one given instance of Impl.
2260 template <typename F, typename Impl>
2261 ::testing::Action<F> MakeAction(std::shared_ptr<Impl> impl) {
2262   return ::testing::Action<F>(ActionImpl<F, Impl>(std::move(impl)));
2263 }
2264 
2265 #define GMOCK_INTERNAL_ARG_UNUSED(i, data, el) \
2266   , [[maybe_unused]] const arg##i##_type& arg##i
2267 #define GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_          \
2268   [[maybe_unused]] const args_type& args GMOCK_PP_REPEAT( \
2269       GMOCK_INTERNAL_ARG_UNUSED, , 10)
2270 
2271 #define GMOCK_INTERNAL_ARG(i, data, el) , const arg##i##_type& arg##i
2272 #define GMOCK_ACTION_ARG_TYPES_AND_NAMES_ \
2273   const args_type& args GMOCK_PP_REPEAT(GMOCK_INTERNAL_ARG, , 10)
2274 
2275 #define GMOCK_INTERNAL_TEMPLATE_ARG(i, data, el) , typename arg##i##_type
2276 #define GMOCK_ACTION_TEMPLATE_ARGS_NAMES_ \
2277   GMOCK_PP_TAIL(GMOCK_PP_REPEAT(GMOCK_INTERNAL_TEMPLATE_ARG, , 10))
2278 
2279 #define GMOCK_INTERNAL_TYPENAME_PARAM(i, data, param) , typename param##_type
2280 #define GMOCK_ACTION_TYPENAME_PARAMS_(params) \
2281   GMOCK_PP_TAIL(GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_TYPENAME_PARAM, , params))
2282 
2283 #define GMOCK_INTERNAL_TYPE_PARAM(i, data, param) , param##_type
2284 #define GMOCK_ACTION_TYPE_PARAMS_(params) \
2285   GMOCK_PP_TAIL(GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_TYPE_PARAM, , params))
2286 
2287 #define GMOCK_INTERNAL_TYPE_GVALUE_PARAM(i, data, param) \
2288   , param##_type gmock_p##i
2289 #define GMOCK_ACTION_TYPE_GVALUE_PARAMS_(params) \
2290   GMOCK_PP_TAIL(GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_TYPE_GVALUE_PARAM, , params))
2291 
2292 #define GMOCK_INTERNAL_GVALUE_PARAM(i, data, param) \
2293   , std::forward<param##_type>(gmock_p##i)
2294 #define GMOCK_ACTION_GVALUE_PARAMS_(params) \
2295   GMOCK_PP_TAIL(GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_GVALUE_PARAM, , params))
2296 
2297 #define GMOCK_INTERNAL_INIT_PARAM(i, data, param) \
2298   , param(::std::forward<param##_type>(gmock_p##i))
2299 #define GMOCK_ACTION_INIT_PARAMS_(params) \
2300   GMOCK_PP_TAIL(GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_INIT_PARAM, , params))
2301 
2302 #define GMOCK_INTERNAL_FIELD_PARAM(i, data, param) param##_type param;
2303 #define GMOCK_ACTION_FIELD_PARAMS_(params) \
2304   GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_FIELD_PARAM, , params)
2305 
2306 #define GMOCK_INTERNAL_ACTION(name, full_name, params)                         \
2307   template <GMOCK_ACTION_TYPENAME_PARAMS_(params)>                             \
2308   class full_name {                                                            \
2309    public:                                                                     \
2310     explicit full_name(GMOCK_ACTION_TYPE_GVALUE_PARAMS_(params))               \
2311         : impl_(std::make_shared<gmock_Impl>(                                  \
2312               GMOCK_ACTION_GVALUE_PARAMS_(params))) {}                         \
2313     full_name(const full_name&) = default;                                     \
2314     full_name(full_name&&) noexcept = default;                                 \
2315     template <typename F>                                                      \
2316     operator ::testing::Action<F>() const {                                    \
2317       return ::testing::internal::MakeAction<F>(impl_);                        \
2318     }                                                                          \
2319                                                                                \
2320    private:                                                                    \
2321     class gmock_Impl {                                                         \
2322      public:                                                                   \
2323       explicit gmock_Impl(GMOCK_ACTION_TYPE_GVALUE_PARAMS_(params))            \
2324           : GMOCK_ACTION_INIT_PARAMS_(params) {}                               \
2325       template <typename function_type, typename return_type,                  \
2326                 typename args_type, GMOCK_ACTION_TEMPLATE_ARGS_NAMES_>         \
2327       return_type gmock_PerformImpl(GMOCK_ACTION_ARG_TYPES_AND_NAMES_) const;  \
2328       GMOCK_ACTION_FIELD_PARAMS_(params)                                       \
2329     };                                                                         \
2330     std::shared_ptr<const gmock_Impl> impl_;                                   \
2331   };                                                                           \
2332   template <GMOCK_ACTION_TYPENAME_PARAMS_(params)>                             \
2333   [[nodiscard]] inline full_name<GMOCK_ACTION_TYPE_PARAMS_(params)> name(      \
2334       GMOCK_ACTION_TYPE_GVALUE_PARAMS_(params));                               \
2335   template <GMOCK_ACTION_TYPENAME_PARAMS_(params)>                             \
2336   inline full_name<GMOCK_ACTION_TYPE_PARAMS_(params)> name(                    \
2337       GMOCK_ACTION_TYPE_GVALUE_PARAMS_(params)) {                              \
2338     return full_name<GMOCK_ACTION_TYPE_PARAMS_(params)>(                       \
2339         GMOCK_ACTION_GVALUE_PARAMS_(params));                                  \
2340   }                                                                            \
2341   template <GMOCK_ACTION_TYPENAME_PARAMS_(params)>                             \
2342   template <typename function_type, typename return_type, typename args_type,  \
2343             GMOCK_ACTION_TEMPLATE_ARGS_NAMES_>                                 \
2344   return_type                                                                  \
2345   full_name<GMOCK_ACTION_TYPE_PARAMS_(params)>::gmock_Impl::gmock_PerformImpl( \
2346       GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
2347 
2348 }  // namespace internal
2349 
2350 // Similar to GMOCK_INTERNAL_ACTION, but no bound parameters are stored.
2351 #define ACTION(name)                                                          \
2352   class name##Action {                                                        \
2353    public:                                                                    \
2354     explicit name##Action() noexcept {}                                       \
2355     name##Action(const name##Action&) noexcept {}                             \
2356     template <typename F>                                                     \
2357     operator ::testing::Action<F>() const {                                   \
2358       return ::testing::internal::MakeAction<F, gmock_Impl>();                \
2359     }                                                                         \
2360                                                                               \
2361    private:                                                                   \
2362     class gmock_Impl {                                                        \
2363      public:                                                                  \
2364       template <typename function_type, typename return_type,                 \
2365                 typename args_type, GMOCK_ACTION_TEMPLATE_ARGS_NAMES_>        \
2366       return_type gmock_PerformImpl(GMOCK_ACTION_ARG_TYPES_AND_NAMES_) const; \
2367     };                                                                        \
2368   };                                                                          \
2369   [[nodiscard]] inline name##Action name();                                   \
2370   inline name##Action name() { return name##Action(); }                       \
2371   template <typename function_type, typename return_type, typename args_type, \
2372             GMOCK_ACTION_TEMPLATE_ARGS_NAMES_>                                \
2373   return_type name##Action::gmock_Impl::gmock_PerformImpl(                    \
2374       GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
2375 
2376 #define ACTION_P(name, ...) \
2377   GMOCK_INTERNAL_ACTION(name, name##ActionP, (__VA_ARGS__))
2378 
2379 #define ACTION_P2(name, ...) \
2380   GMOCK_INTERNAL_ACTION(name, name##ActionP2, (__VA_ARGS__))
2381 
2382 #define ACTION_P3(name, ...) \
2383   GMOCK_INTERNAL_ACTION(name, name##ActionP3, (__VA_ARGS__))
2384 
2385 #define ACTION_P4(name, ...) \
2386   GMOCK_INTERNAL_ACTION(name, name##ActionP4, (__VA_ARGS__))
2387 
2388 #define ACTION_P5(name, ...) \
2389   GMOCK_INTERNAL_ACTION(name, name##ActionP5, (__VA_ARGS__))
2390 
2391 #define ACTION_P6(name, ...) \
2392   GMOCK_INTERNAL_ACTION(name, name##ActionP6, (__VA_ARGS__))
2393 
2394 #define ACTION_P7(name, ...) \
2395   GMOCK_INTERNAL_ACTION(name, name##ActionP7, (__VA_ARGS__))
2396 
2397 #define ACTION_P8(name, ...) \
2398   GMOCK_INTERNAL_ACTION(name, name##ActionP8, (__VA_ARGS__))
2399 
2400 #define ACTION_P9(name, ...) \
2401   GMOCK_INTERNAL_ACTION(name, name##ActionP9, (__VA_ARGS__))
2402 
2403 #define ACTION_P10(name, ...) \
2404   GMOCK_INTERNAL_ACTION(name, name##ActionP10, (__VA_ARGS__))
2405 
2406 }  // namespace testing
2407 
2408 GTEST_DISABLE_MSC_WARNINGS_POP_()  // 4100
2409 
2410 #endif  // GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_