diff --git a/googlemock/include/gmock/gmock-actions.h b/googlemock/include/gmock/gmock-actions.h index fe3b41ca..94552cea 100644 --- a/googlemock/include/gmock/gmock-actions.h +++ b/googlemock/include/gmock/gmock-actions.h @@ -196,7 +196,7 @@ struct BuiltInDefaultValueGetter { // other type T, the built-in default T value is undefined, and the // function will abort the process. template -class BuiltInDefaultValue { +class [[nodiscard]] BuiltInDefaultValue { public: // This function returns true if and only if type T has a built-in default // value. @@ -211,7 +211,7 @@ class BuiltInDefaultValue { // This partial specialization says that we use the same built-in // default value for T and const T. template -class BuiltInDefaultValue { +class [[nodiscard]] BuiltInDefaultValue { public: static bool Exists() { return BuiltInDefaultValue::Exists(); } static T Get() { return BuiltInDefaultValue::Get(); } @@ -220,7 +220,7 @@ class BuiltInDefaultValue { // This partial specialization defines the default values for pointer // types. template -class BuiltInDefaultValue { +class [[nodiscard]] BuiltInDefaultValue { public: static bool Exists() { return true; } static T* Get() { return nullptr; } @@ -383,7 +383,7 @@ typename std::add_const::type& as_const(T& t) { // Specialized for function types below. template -class OnceAction; +class [[nodiscard]] OnceAction; // An action that can only be used once. // @@ -421,7 +421,7 @@ class OnceAction; // A less-contrived example would be an action that returns an arbitrary type, // whose &&-qualified call operator is capable of dealing with move-only types. template -class OnceAction final { +class [[nodiscard]] OnceAction final { private: // True iff we can use the given callable type (or lvalue reference) directly // via StdFunctionAdaptor. @@ -574,7 +574,7 @@ class OnceAction final { // // Sets the default value for type T to be foo. // DefaultValue::Set(foo); template -class DefaultValue { +class [[nodiscard]] DefaultValue { public: // Sets the default value for type T; requires T to be // copy-constructable and have a public destructor. @@ -651,7 +651,7 @@ class DefaultValue { // This partial specialization allows a user to set default values for // reference types. template -class DefaultValue { +class [[nodiscard]] DefaultValue { public: // Sets the default value for type T&. static void Set(T& x) { // NOLINT @@ -685,7 +685,7 @@ class DefaultValue { // This specialization allows DefaultValue::Get() to // compile. template <> -class DefaultValue { +class [[nodiscard]] DefaultValue { public: static bool Exists() { return true; } static void Get() {} @@ -701,7 +701,7 @@ T* DefaultValue::address_ = nullptr; // Implement this interface to define an action for function type F. template -class ActionInterface { +class [[nodiscard]] ActionInterface { public: typedef typename internal::Function::Result Result; typedef typename internal::Function::ArgumentTuple ArgumentTuple; @@ -721,7 +721,7 @@ class ActionInterface { }; template -class Action; +class [[nodiscard]] Action; // An Action is a copyable and IMMUTABLE (except by assignment) // object that represents an action to be taken when a mock function of type @@ -730,7 +730,7 @@ class Action; // can view an object implementing ActionInterface as a concrete action // (including its current state), and an Action object as a handle to it. template -class Action { +class [[nodiscard]] Action { private: using F = R(Args...); @@ -869,7 +869,7 @@ class Action { // the definition of Return(void) and SetArgumentPointee(value) for // complete examples. template -class PolymorphicAction { +class [[nodiscard]] PolymorphicAction { public: explicit PolymorphicAction(const Impl& impl) : impl_(impl) {} @@ -929,7 +929,7 @@ struct ByMoveWrapper { // The general implementation of Return(R). Specializations follow below. template -class ReturnAction final { +class [[nodiscard]] ReturnAction final { public: explicit ReturnAction(R value) : value_(std::move(value)) {} @@ -1095,7 +1095,7 @@ class ReturnAction final { // the const call operator, checking at runtime that it isn't called more than // once, since the user has declared their intent to do so by using ByMove. template -class ReturnAction> final { +class [[nodiscard]] ReturnAction> final { public: explicit ReturnAction(ByMoveWrapper wrapper) : state_(new State(std::move(wrapper.payload))) {} @@ -1122,7 +1122,7 @@ class ReturnAction> final { }; // Implements the ReturnNull() action. -class ReturnNullAction { +class [[nodiscard]] ReturnNullAction { public: // Allows ReturnNull() to be used in any pointer-returning function. In C++11 // this is enforced by returning nullptr, and in non-C++11 by asserting a @@ -1134,7 +1134,7 @@ class ReturnNullAction { }; // Implements the Return() action. -class ReturnVoidAction { +class [[nodiscard]] ReturnVoidAction { public: // Allows Return() to be used in any void-returning function. template @@ -1147,7 +1147,7 @@ class ReturnVoidAction { // in any function that returns a reference to the type of x, // regardless of the argument types. template -class ReturnRefAction { +class [[nodiscard]] ReturnRefAction { public: // Constructs a ReturnRefAction object from the reference to be returned. explicit ReturnRefAction(T& ref) : ref_(ref) {} // NOLINT @@ -1188,7 +1188,7 @@ class ReturnRefAction { // used in any function that returns a reference to the type of x, // regardless of the argument types. template -class ReturnRefOfCopyAction { +class [[nodiscard]] ReturnRefOfCopyAction { public: // Constructs a ReturnRefOfCopyAction object from the reference to // be returned. @@ -1229,7 +1229,7 @@ class ReturnRefOfCopyAction { // Implements the polymorphic ReturnRoundRobin(v) action, which can be // used in any function that returns the element_type of v. template -class ReturnRoundRobinAction { +class [[nodiscard]] ReturnRoundRobinAction { public: explicit ReturnRoundRobinAction(std::vector values) { GTEST_CHECK_(!values.empty()) @@ -1257,7 +1257,7 @@ class ReturnRoundRobinAction { }; // Implements the polymorphic DoDefault() action. -class DoDefaultAction { +class [[nodiscard]] DoDefaultAction { public: // This template type conversion operator allows DoDefault() to be // used in any function. @@ -1270,7 +1270,7 @@ class DoDefaultAction { // Implements the Assign action to set a given pointer referent to a // particular value. template -class AssignAction { +class [[nodiscard]] AssignAction { public: AssignAction(T1* ptr, T2 value) : ptr_(ptr), value_(value) {} @@ -1289,7 +1289,7 @@ class AssignAction { // Implements the SetErrnoAndReturn action to simulate return from // various system calls and libc functions. template -class SetErrnoAndReturnAction { +class [[nodiscard]] SetErrnoAndReturnAction { public: SetErrnoAndReturnAction(int errno_value, T result) : errno_(errno_value), result_(result) {} @@ -1397,7 +1397,7 @@ class IgnoreResultAction { void Perform(const ArgumentTuple& args) override { // Performs the action and ignores its result. - action_.Perform(args); + (void)action_.Perform(args); } private: @@ -1503,11 +1503,11 @@ struct WithArgsAction { }; template -class DoAllAction; +class [[nodiscard]] DoAllAction; // Base case: only a single action. template -class DoAllAction { +class [[nodiscard]] DoAllAction { public: struct UserConstructorTag {}; @@ -1561,7 +1561,7 @@ class DoAllAction { // Recursive case: support N actions by calling the initial action and then // calling through to the base class containing N-1 actions. template -class DoAllAction +class [[nodiscard]] DoAllAction : private DoAllAction { private: using Base = DoAllAction; @@ -1796,7 +1796,7 @@ struct SetArrayArgumentAction { }; template -class DeleteArgAction { +class [[nodiscard]] DeleteArgAction { public: template void operator()(const Args&... args) const { diff --git a/googlemock/include/gmock/gmock-cardinalities.h b/googlemock/include/gmock/gmock-cardinalities.h index 533e604f..c88c00c4 100644 --- a/googlemock/include/gmock/gmock-cardinalities.h +++ b/googlemock/include/gmock/gmock-cardinalities.h @@ -63,7 +63,7 @@ namespace testing { // management as Cardinality objects can now be copied like plain values. // The implementation of a cardinality. -class CardinalityInterface { +class [[nodiscard]] CardinalityInterface { public: virtual ~CardinalityInterface() = default; @@ -88,7 +88,7 @@ class CardinalityInterface { // object that specifies how many times a mock function is expected to // be called. The implementation of Cardinality is just a std::shared_ptr // to const CardinalityInterface. Don't inherit from Cardinality! -class GTEST_API_ Cardinality { +class GTEST_API_ [[nodiscard]] Cardinality { public: // Constructs a null cardinality. Needed for storing Cardinality // objects in STL containers. diff --git a/googlemock/include/gmock/gmock-matchers.h b/googlemock/include/gmock/gmock-matchers.h index 666baaf7..60ddeabc 100644 --- a/googlemock/include/gmock/gmock-matchers.h +++ b/googlemock/include/gmock/gmock-matchers.h @@ -303,7 +303,7 @@ namespace testing { // plain values. // A match result listener that stores the explanation in a string. -class StringMatchResultListener : public MatchResultListener { +class [[nodiscard]] StringMatchResultListener : public MatchResultListener { public: StringMatchResultListener() : MatchResultListener(&ss_) {} @@ -336,7 +336,7 @@ namespace internal { // Matcher but is not one yet; for example, Eq(value)) or a value (for // example, "hello"). template -class MatcherCastImpl { +class [[nodiscard]] MatcherCastImpl { public: static Matcher Cast(const M& polymorphic_matcher_or_value) { // M can be a polymorphic matcher, in which case we want to use @@ -406,7 +406,7 @@ class MatcherCastImpl { // is already a Matcher. This only compiles when type T can be // statically converted to type U. template -class MatcherCastImpl> { +class [[nodiscard]] MatcherCastImpl> { public: static Matcher Cast(const Matcher& source_matcher) { return Matcher(new Impl(source_matcher)); @@ -468,14 +468,14 @@ class MatcherCastImpl> { // This even more specialized version is used for efficiently casting // a matcher to its own type. template -class MatcherCastImpl> { +class [[nodiscard]] MatcherCastImpl> { public: static Matcher Cast(const Matcher& matcher) { return matcher; } }; // Template specialization for parameterless Matcher. template -class MatcherBaseImpl { +class [[nodiscard]] MatcherBaseImpl { public: MatcherBaseImpl() = default; @@ -488,7 +488,7 @@ class MatcherBaseImpl { // Template specialization for Matcher with parameters. template