Skip to content

Commit 26d391c

Browse files
committed
Intermediate changes
commit_hash:e109e4e334fdc9ac21071bf6c37ddf3be36a335e
1 parent 611e4b0 commit 26d391c

22 files changed

+939
-390
lines changed

contrib/restricted/googletest/googlemock/include/gmock/gmock-actions.h

Lines changed: 101 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -835,6 +835,10 @@ class Action<R(Args...)> {
835835
Result operator()(const InArgs&...) const {
836836
return function_impl();
837837
}
838+
template <typename... InArgs>
839+
Result operator()(const InArgs&...) {
840+
return function_impl();
841+
}
838842

839843
FunctionImpl function_impl;
840844
};
@@ -1451,6 +1455,30 @@ struct WithArgsAction {
14511455
return OA{std::move(inner_action)};
14521456
}
14531457

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+
14541482
template <
14551483
typename R, typename... Args,
14561484
typename std::enable_if<
@@ -1493,6 +1521,7 @@ class DoAllAction<FinalAction> {
14931521
// providing a call operator because even with a particular set of arguments
14941522
// they don't have a fixed return type.
14951523

1524+
// We support conversion to OnceAction whenever the sub-action does.
14961525
template <typename R, typename... Args,
14971526
typename std::enable_if<
14981527
std::is_convertible<FinalAction, OnceAction<R(Args...)>>::value,
@@ -1501,6 +1530,21 @@ class DoAllAction<FinalAction> {
15011530
return std::move(final_action_);
15021531
}
15031532

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.
15041548
template <
15051549
typename R, typename... Args,
15061550
typename std::enable_if<
@@ -1580,16 +1624,16 @@ class DoAllAction<InitialAction, OtherActions...>
15801624
: Base({}, std::forward<U>(other_actions)...),
15811625
initial_action_(std::forward<T>(initial_action)) {}
15821626

1583-
template <typename R, typename... Args,
1584-
typename std::enable_if<
1585-
conjunction<
1586-
// Both the initial action and the rest must support
1587-
// conversion to OnceAction.
1588-
std::is_convertible<
1589-
InitialAction,
1590-
OnceAction<void(InitialActionArgType<Args>...)>>,
1591-
std::is_convertible<Base, OnceAction<R(Args...)>>>::value,
1592-
int>::type = 0>
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>
15931637
operator OnceAction<R(Args...)>() && { // NOLINT
15941638
// Return an action that first calls the initial action with arguments
15951639
// filtered through InitialActionArgType, then forwards arguments directly
@@ -1612,12 +1656,34 @@ class DoAllAction<InitialAction, OtherActions...>
16121656
};
16131657
}
16141658

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.
16151683
template <
16161684
typename R, typename... Args,
16171685
typename std::enable_if<
16181686
conjunction<
1619-
// Both the initial action and the rest must support conversion to
1620-
// Action.
16211687
std::is_convertible<const InitialAction&,
16221688
Action<void(InitialActionArgType<Args>...)>>,
16231689
std::is_convertible<const Base&, Action<R(Args...)>>>::value,
@@ -1681,6 +1747,16 @@ struct SaveArgAction {
16811747
}
16821748
};
16831749

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+
16841760
template <size_t k, typename Ptr>
16851761
struct SaveArgPointeeAction {
16861762
Ptr pointer;
@@ -2031,6 +2107,13 @@ internal::SaveArgAction<k, Ptr> SaveArg(Ptr pointer) {
20312107
return {pointer};
20322108
}
20332109

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+
20342117
// Action SaveArgPointee<k>(pointer) saves the value pointed to
20352118
// by the k-th (0-based) argument of the mock function to *pointer.
20362119
template <size_t k, typename Ptr>
@@ -2174,9 +2257,9 @@ ::testing::Action<F> MakeAction(std::shared_ptr<Impl> impl) {
21742257
}
21752258

21762259
#define GMOCK_INTERNAL_ARG_UNUSED(i, data, el) \
2177-
, GTEST_INTERNAL_ATTRIBUTE_MAYBE_UNUSED const arg##i##_type& arg##i
2178-
#define GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_ \
2179-
GTEST_INTERNAL_ATTRIBUTE_MAYBE_UNUSED const args_type& args GMOCK_PP_REPEAT( \
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( \
21802263
GMOCK_INTERNAL_ARG_UNUSED, , 10)
21812264

21822265
#define GMOCK_INTERNAL_ARG(i, data, el) , const arg##i##_type& arg##i
@@ -2241,8 +2324,8 @@ ::testing::Action<F> MakeAction(std::shared_ptr<Impl> impl) {
22412324
std::shared_ptr<const gmock_Impl> impl_; \
22422325
}; \
22432326
template <GMOCK_ACTION_TYPENAME_PARAMS_(params)> \
2244-
inline full_name<GMOCK_ACTION_TYPE_PARAMS_(params)> name( \
2245-
GMOCK_ACTION_TYPE_GVALUE_PARAMS_(params)) GTEST_MUST_USE_RESULT_; \
2327+
[[nodiscard]] inline full_name<GMOCK_ACTION_TYPE_PARAMS_(params)> name( \
2328+
GMOCK_ACTION_TYPE_GVALUE_PARAMS_(params)); \
22462329
template <GMOCK_ACTION_TYPENAME_PARAMS_(params)> \
22472330
inline full_name<GMOCK_ACTION_TYPE_PARAMS_(params)> name( \
22482331
GMOCK_ACTION_TYPE_GVALUE_PARAMS_(params)) { \
@@ -2277,7 +2360,7 @@ ::testing::Action<F> MakeAction(std::shared_ptr<Impl> impl) {
22772360
return_type gmock_PerformImpl(GMOCK_ACTION_ARG_TYPES_AND_NAMES_) const; \
22782361
}; \
22792362
}; \
2280-
inline name##Action name() GTEST_MUST_USE_RESULT_; \
2363+
[[nodiscard]] inline name##Action name(); \
22812364
inline name##Action name() { return name##Action(); } \
22822365
template <typename function_type, typename return_type, typename args_type, \
22832366
GMOCK_ACTION_TEMPLATE_ARGS_NAMES_> \

0 commit comments

Comments
 (0)