summaryrefslogtreecommitdiffstats
path: root/googlemock/include/gmock
diff options
context:
space:
mode:
authorAbseil Team <absl-team@google.com>2020-09-08 23:45:18 (GMT)
committerDerek Mauro <dmauro@google.com>2020-09-10 23:09:30 (GMT)
commita4ab0abb93620ce26efad9de9296b73b16e88588 (patch)
treed58fdee30831454feac16fdbe5693a66914c03fa /googlemock/include/gmock
parent646603961bf88f8b07e5da952612cfe1e0e020fa (diff)
downloadgoogletest-a4ab0abb93620ce26efad9de9296b73b16e88588.zip
googletest-a4ab0abb93620ce26efad9de9296b73b16e88588.tar.gz
googletest-a4ab0abb93620ce26efad9de9296b73b16e88588.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: 330614454
Diffstat (limited to 'googlemock/include/gmock')
-rw-r--r--googlemock/include/gmock/gmock-actions.h4
-rw-r--r--googlemock/include/gmock/gmock-generated-actions.h25
-rw-r--r--googlemock/include/gmock/gmock-generated-actions.h.pump22
3 files changed, 50 insertions, 1 deletions
diff --git a/googlemock/include/gmock/gmock-actions.h b/googlemock/include/gmock/gmock-actions.h
index d934dc9..cdff694 100644
--- a/googlemock/include/gmock/gmock-actions.h
+++ b/googlemock/include/gmock/gmock-actions.h
@@ -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_> \
diff --git a/googlemock/include/gmock/gmock-generated-actions.h b/googlemock/include/gmock/gmock-generated-actions.h
index ccae611..124bd01 100644
--- a/googlemock/include/gmock/gmock-generated-actions.h
+++ b/googlemock/include/gmock/gmock-generated-actions.h
@@ -294,6 +294,20 @@
p7(::std::move(gmock_p7)), p8(::std::move(gmock_p8)), \
p9(::std::move(gmock_p9))
+// Defines the copy constructor
+#define GMOCK_INTERNAL_DEFN_COPY_AND_0_VALUE_PARAMS() \
+ {} // Work around https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82134
+#define GMOCK_INTERNAL_DEFN_COPY_AND_1_VALUE_PARAMS(...) = default;
+#define GMOCK_INTERNAL_DEFN_COPY_AND_2_VALUE_PARAMS(...) = default;
+#define GMOCK_INTERNAL_DEFN_COPY_AND_3_VALUE_PARAMS(...) = default;
+#define GMOCK_INTERNAL_DEFN_COPY_AND_4_VALUE_PARAMS(...) = default;
+#define GMOCK_INTERNAL_DEFN_COPY_AND_5_VALUE_PARAMS(...) = default;
+#define GMOCK_INTERNAL_DEFN_COPY_AND_6_VALUE_PARAMS(...) = default;
+#define GMOCK_INTERNAL_DEFN_COPY_AND_7_VALUE_PARAMS(...) = default;
+#define GMOCK_INTERNAL_DEFN_COPY_AND_8_VALUE_PARAMS(...) = default;
+#define GMOCK_INTERNAL_DEFN_COPY_AND_9_VALUE_PARAMS(...) = default;
+#define GMOCK_INTERNAL_DEFN_COPY_AND_10_VALUE_PARAMS(...) = default;
+
// Declares the fields for storing the value parameters.
#define GMOCK_INTERNAL_DEFN_AND_0_VALUE_PARAMS()
#define GMOCK_INTERNAL_DEFN_AND_1_VALUE_PARAMS(p0) p0##_type p0;
@@ -422,6 +436,11 @@
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:\
@@ -446,6 +465,12 @@
};\
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\
GMOCK_INTERNAL_LIST_TYPE_##value_params> name(\
diff --git a/googlemock/include/gmock/gmock-generated-actions.h.pump b/googlemock/include/gmock/gmock-generated-actions.h.pump
index 1512d72..7a7fc9f 100644
--- a/googlemock/include/gmock/gmock-generated-actions.h.pump
+++ b/googlemock/include/gmock/gmock-generated-actions.h.pump
@@ -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
@@ -178,6 +177,16 @@ $range j 0..i-1
]]
+// 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.
$for i [[
@@ -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:\
@@ -265,6 +279,12 @@ $range k 0..n-1
};\
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\
GMOCK_INTERNAL_LIST_TYPE_##value_params> name(\