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

@@ -55,7 +55,6 @@ $$}} This meta comment fixes auto-indentation in editors.
$range i 0..n
$range k 0..n-1
// Sometimes you want to give an action explicit template parameters
// that cannot be inferred from its value parameters. ACTION() and
// ACTION_P*() don't support that. ACTION_TEMPLATE() remedies that
@@ -176,6 +175,16 @@ $range j 0..i-1
($for j, [[p$j##_type gmock_p$j]])$if i>0 [[ : ]]$for j, [[p$j(::std::move(gmock_p$j))]]
]]
// Defines the copy constructor
$for i [[
#define GMOCK_INTERNAL_DEFN_COPY_AND_$i[[]]_VALUE_PARAMS$if i == 0[[() \
{} // Work around https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82134
]] $else [[(...) = default;]]
]]
// Declares the fields for storing the value parameters.
@@ -241,6 +250,11 @@ $range k 0..n-1
public:\
explicit GMOCK_ACTION_CLASS_(name, value_params)\
GMOCK_INTERNAL_INIT_##value_params {}\
GMOCK_ACTION_CLASS_(name, value_params)(\
const GMOCK_ACTION_CLASS_(name, value_params)<\
GMOCK_INTERNAL_LIST_##template_params\
GMOCK_INTERNAL_LIST_TYPE_##value_params>&)\
GMOCK_INTERNAL_DEFN_COPY_##value_params\
template <typename F>\
class gmock_Impl : public ::testing::ActionInterface<F> {\
public:\
@@ -263,6 +277,12 @@ $range k 0..n-1
}\
GMOCK_INTERNAL_DEFN_##value_params\
};\
template <GMOCK_INTERNAL_DECL_##template_params\
GMOCK_INTERNAL_DECL_TYPE_##value_params>\
GMOCK_ACTION_CLASS_(name, value_params)<\
GMOCK_INTERNAL_LIST_##template_params\
GMOCK_INTERNAL_LIST_TYPE_##value_params> name(\
GMOCK_INTERNAL_DECL_##value_params) GTEST_MUST_USE_RESULT_;\
template <GMOCK_INTERNAL_DECL_##template_params\
GMOCK_INTERNAL_DECL_TYPE_##value_params>\
inline GMOCK_ACTION_CLASS_(name, value_params)<\