From ae1b7ad4308249bfa928e65d1a33be117fc0992c Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Tue, 8 Mar 2022 06:41:34 -0800 Subject: 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 --- googlemock/include/gmock/gmock-actions.h | 3 +++ 1 file changed, 3 insertions(+) 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 }; \ template \ inline full_name name( \ + GMOCK_ACTION_TYPE_GVALUE_PARAMS_(params)) GTEST_MUST_USE_RESULT_; \ + template \ + inline full_name name( \ GMOCK_ACTION_TYPE_GVALUE_PARAMS_(params)) { \ return full_name( \ GMOCK_ACTION_GVALUE_PARAMS_(params)); \ -- cgit v0.12