Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-17 09:00:40

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