Googletest export

Mark ACTION_Pn()-generated functions as must-use-result.

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*)` and `ACTION(Use) { Use(arg); }` for later application to a Foo.  With such an overload, a client may then write `Use();`, forgetting the param and being confused why nothing happens.

This also catches when a client defines their own action in terms of an ACTION()-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: 330614454
This commit is contained in:
Abseil Team
2020-09-08 19:45:18 -04:00
committed by Derek Mauro
parent 646603961b
commit a4ab0abb93
3 changed files with 50 additions and 1 deletions

View File

@@ -1637,6 +1637,9 @@ auto InvokeArgument(F f, Args... args) -> decltype(f(args...)) {
\
public: \
using base_type::base_type; \
name##Action() = default; \
/* Work around https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82134 */ \
name##Action(const name##Action&) { } \
template <typename F> \
class gmock_Impl : public ::testing::ActionInterface<F> { \
public: \
@@ -1654,6 +1657,7 @@ auto InvokeArgument(F f, Args... args) -> decltype(f(args...)) {
return_type gmock_PerformImpl(GMOCK_ACTION_ARG_TYPES_AND_NAMES_) const; \
}; \
}; \
inline name##Action name() GTEST_MUST_USE_RESULT_; \
inline name##Action name() { return name##Action(); } \
template <typename F> \
template <GMOCK_ACTION_TEMPLATE_ARGS_NAMES_> \