summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAbseil Team <absl-team@google.com>2022-03-08 14:41:34 (GMT)
committerCopybara-Service <copybara-worker@google.com>2022-03-08 14:42:11 (GMT)
commitae1b7ad4308249bfa928e65d1a33be117fc0992c (patch)
tree6488d769a5cfe432aa95394d2f437e8ae9b17ed5
parentc9461a9b55ba954df0489bab6420eb297bed846b (diff)
downloadgoogletest-ae1b7ad4308249bfa928e65d1a33be117fc0992c.zip
googletest-ae1b7ad4308249bfa928e65d1a33be117fc0992c.tar.gz
googletest-ae1b7ad4308249bfa928e65d1a33be117fc0992c.tar.bz2
Mark ACTION_Pn()-generated functions as must-use-result, adding non-compilation tests.
This catches when a client creates an action and discards it, thinking that the action has actually been applied to something. This will help people who make the mistake of defining, for example, both `void Use(Foo*, Bar)` and `ACTION_P(Use, bar) { Use(arg, bar); }` for later application to a Foo. With such an overload, a client may then write `Use(bar);`, selecting the Action<> overload and being confused why nothing happens. This also catches when a client defines their own action in terms of an ACTION_P()-generated one, invokes the Action<>'s builder, and then fails to invoke the resulting action, thinking it's operating on the outer action's parameters. PiperOrigin-RevId: 433197479 Change-Id: I98e4389150d01a5e753230113016d9fc38b1d260
-rw-r--r--googlemock/include/gmock/gmock-actions.h3
1 files changed, 3 insertions, 0 deletions
diff --git a/googlemock/include/gmock/gmock-actions.h b/googlemock/include/gmock/gmock-actions.h
index 70c325a..035b66b 100644
--- a/googlemock/include/gmock/gmock-actions.h
+++ b/googlemock/include/gmock/gmock-actions.h
@@ -1611,6 +1611,9 @@ template <typename F, typename Impl>
}; \
template <GMOCK_ACTION_TYPENAME_PARAMS_(params)> \
inline full_name<GMOCK_ACTION_TYPE_PARAMS_(params)> name( \
+ GMOCK_ACTION_TYPE_GVALUE_PARAMS_(params)) GTEST_MUST_USE_RESULT_; \
+ template <GMOCK_ACTION_TYPENAME_PARAMS_(params)> \
+ inline full_name<GMOCK_ACTION_TYPE_PARAMS_(params)> name( \
GMOCK_ACTION_TYPE_GVALUE_PARAMS_(params)) { \
return full_name<GMOCK_ACTION_TYPE_PARAMS_(params)>( \
GMOCK_ACTION_GVALUE_PARAMS_(params)); \