summaryrefslogtreecommitdiffstats
path: root/googlemock
diff options
context:
space:
mode:
authorAbseil Team <absl-team@google.com>2020-05-18 17:36:30 (GMT)
committerDerek Mauro <dmauro@google.com>2020-05-28 23:53:34 (GMT)
commit1397db9e5833796d206896323ae50d6dc617d6e2 (patch)
tree8cec974caefaaf6c8e5f27da1051a0511f0acc54 /googlemock
parent63713e1ce49019da205daa1ca91b73fcfc9b333f (diff)
downloadgoogletest-1397db9e5833796d206896323ae50d6dc617d6e2.zip
googletest-1397db9e5833796d206896323ae50d6dc617d6e2.tar.gz
googletest-1397db9e5833796d206896323ae50d6dc617d6e2.tar.bz2
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: 312108101
Diffstat (limited to 'googlemock')
-rw-r--r--googlemock/include/gmock/gmock-actions.h1
-rw-r--r--googlemock/include/gmock/gmock-generated-actions.h8
-rw-r--r--googlemock/include/gmock/gmock-generated-actions.h.pump8
3 files changed, 15 insertions, 2 deletions
diff --git a/googlemock/include/gmock/gmock-actions.h b/googlemock/include/gmock/gmock-actions.h
index ecf47c4..e87296e 100644
--- a/googlemock/include/gmock/gmock-actions.h
+++ b/googlemock/include/gmock/gmock-actions.h
@@ -1512,6 +1512,7 @@ auto InvokeArgumentAdl(AdlTag, 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_> \
diff --git a/googlemock/include/gmock/gmock-generated-actions.h b/googlemock/include/gmock/gmock-generated-actions.h
index 7030a98..4c1584b 100644
--- a/googlemock/include/gmock/gmock-generated-actions.h
+++ b/googlemock/include/gmock/gmock-generated-actions.h
@@ -442,7 +442,13 @@
}\
GMOCK_INTERNAL_DEFN_##value_params\
};\
- template <GMOCK_INTERNAL_DECL_##template_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)<\
GMOCK_INTERNAL_LIST_##template_params\
diff --git a/googlemock/include/gmock/gmock-generated-actions.h.pump b/googlemock/include/gmock/gmock-generated-actions.h.pump
index 3430204..a6c5961 100644
--- a/googlemock/include/gmock/gmock-generated-actions.h.pump
+++ b/googlemock/include/gmock/gmock-generated-actions.h.pump
@@ -260,7 +260,13 @@ $range k 0..n-1
}\
GMOCK_INTERNAL_DEFN_##value_params\
};\
- template <GMOCK_INTERNAL_DECL_##template_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)<\
GMOCK_INTERNAL_LIST_##template_params\