@@ -75,7 +75,7 @@ namespace testing {
7575// 2. a factory function that creates a Matcher<T> object from a
7676// FooMatcherMatcher.
7777
78- class MatchResultListener {
78+ class [[nodiscard]] MatchResultListener {
7979 public:
8080 // Creates a listener object with the given underlying ostream. The
8181 // listener does not own the ostream, and does not dereference it
@@ -111,7 +111,7 @@ inline MatchResultListener::~MatchResultListener() = default;
111111
112112// An instance of a subclass of this knows how to describe itself as a
113113// matcher.
114- class GTEST_API_ MatcherDescriberInterface {
114+ class GTEST_API_ [[nodiscard]] MatcherDescriberInterface {
115115 public:
116116 virtual ~MatcherDescriberInterface () = default ;
117117
@@ -137,7 +137,7 @@ class GTEST_API_ MatcherDescriberInterface {
137137
138138// The implementation of a matcher.
139139template <typename T>
140- class MatcherInterface : public MatcherDescriberInterface {
140+ class [[nodiscard]] MatcherInterface : public MatcherDescriberInterface {
141141 public:
142142 // Returns true if and only if the matcher matches x; also explains the
143143 // match result to 'listener' if necessary (see the next paragraph), in
@@ -180,7 +180,7 @@ class MatcherInterface : public MatcherDescriberInterface {
180180namespace internal {
181181
182182// A match result listener that ignores the explanation.
183- class DummyMatchResultListener : public MatchResultListener {
183+ class [[nodiscard]] DummyMatchResultListener : public MatchResultListener {
184184 public:
185185 DummyMatchResultListener () : MatchResultListener (nullptr ) {}
186186
@@ -192,7 +192,7 @@ class DummyMatchResultListener : public MatchResultListener {
192192// A match result listener that forwards the explanation to a given
193193// ostream. The difference between this and MatchResultListener is
194194// that the former is concrete.
195- class StreamMatchResultListener : public MatchResultListener {
195+ class [[nodiscard]] StreamMatchResultListener : public MatchResultListener {
196196 public:
197197 explicit StreamMatchResultListener (::std::ostream* os)
198198 : MatchResultListener (os) {}
@@ -225,7 +225,7 @@ struct SharedPayload : SharedPayloadBase {
225225// from it. We put functionalities common to all Matcher<T>
226226// specializations here to avoid code duplication.
227227template <typename T>
228- class MatcherBase : private MatcherDescriberInterface {
228+ class [[nodiscard]] MatcherBase : private MatcherDescriberInterface {
229229 public:
230230 // Returns true if and only if the matcher matches x; also explains the
231231 // match result to 'listener'.
@@ -460,7 +460,7 @@ class MatcherBase : private MatcherDescriberInterface {
460460// implementation of Matcher<T> is just a std::shared_ptr to const
461461// MatcherInterface<T>. Don't inherit from Matcher!
462462template <typename T>
463- class Matcher : public internal ::MatcherBase<T> {
463+ class [[nodiscard]] Matcher : public internal::MatcherBase<T> {
464464 public:
465465 // Constructs a null matcher. Needed for storing Matcher objects in STL
466466 // containers. A default-constructed matcher is not yet initialized. You
@@ -491,8 +491,8 @@ class Matcher : public internal::MatcherBase<T> {
491491// instead of Eq(str) and "foo" instead of Eq("foo") when a std::string
492492// matcher is expected.
493493template <>
494- class GTEST_API_ Matcher< const std::string&>
495- : public internal::MatcherBase<const std::string&> {
494+ class GTEST_API_ [[nodiscard]]
495+ Matcher< const std::string&> : public internal::MatcherBase<const std::string&> {
496496 public:
497497 Matcher () = default ;
498498
@@ -513,8 +513,8 @@ class GTEST_API_ Matcher<const std::string&>
513513};
514514
515515template <>
516- class GTEST_API_ Matcher<std::string>
517- : public internal::MatcherBase<std::string> {
516+ class GTEST_API_ [[nodiscard]]
517+ Matcher<std::string> : public internal::MatcherBase<std::string> {
518518 public:
519519 Matcher () = default ;
520520
@@ -541,7 +541,7 @@ class GTEST_API_ Matcher<std::string>
541541// instead of Eq(str) and "foo" instead of Eq("foo") when a absl::string_view
542542// matcher is expected.
543543template <>
544- class GTEST_API_ Matcher<const internal::StringView&>
544+ class GTEST_API_ [[nodiscard]] Matcher<const internal::StringView&>
545545 : public internal::MatcherBase<const internal::StringView&> {
546546 public:
547547 Matcher () = default ;
@@ -567,7 +567,7 @@ class GTEST_API_ Matcher<const internal::StringView&>
567567};
568568
569569template <>
570- class GTEST_API_ Matcher<internal::StringView>
570+ class GTEST_API_ [[nodiscard]] Matcher<internal::StringView>
571571 : public internal::MatcherBase<internal::StringView> {
572572 public:
573573 Matcher () = default ;
@@ -614,7 +614,7 @@ std::ostream& operator<<(std::ostream& os, const Matcher<T>& matcher) {
614614//
615615// See the definition of NotNull() for a complete example.
616616template <class Impl >
617- class PolymorphicMatcher {
617+ class [[nodiscard]] PolymorphicMatcher {
618618 public:
619619 explicit PolymorphicMatcher (const Impl& an_impl) : impl_ (an_impl) {}
620620
@@ -689,7 +689,7 @@ namespace internal {
689689// The following template definition assumes that the Rhs parameter is
690690// a "bare" type (i.e. neither 'const T' nor 'T&').
691691template <typename D, typename Rhs, typename Op>
692- class ComparisonBase {
692+ class [[nodiscard]] ComparisonBase {
693693 public:
694694 explicit ComparisonBase (const Rhs& rhs) : rhs_ (rhs) {}
695695
@@ -722,15 +722,16 @@ class ComparisonBase {
722722};
723723
724724template <typename Rhs>
725- class EqMatcher : public ComparisonBase <EqMatcher<Rhs>, Rhs, std::equal_to<>> {
725+ class [[nodiscard]] EqMatcher
726+ : public ComparisonBase<EqMatcher<Rhs>, Rhs, std::equal_to<>> {
726727 public:
727728 explicit EqMatcher (const Rhs& rhs)
728729 : ComparisonBase<EqMatcher<Rhs>, Rhs, std::equal_to<>>(rhs) {}
729730 static const char * Desc () { return " is equal to" ; }
730731 static const char * NegatedDesc () { return " isn't equal to" ; }
731732};
732733template <typename Rhs>
733- class NeMatcher
734+ class [[nodiscard]] NeMatcher
734735 : public ComparisonBase<NeMatcher<Rhs>, Rhs, std::not_equal_to<>> {
735736 public:
736737 explicit NeMatcher (const Rhs& rhs)
@@ -739,23 +740,25 @@ class NeMatcher
739740 static const char * NegatedDesc () { return " is equal to" ; }
740741};
741742template <typename Rhs>
742- class LtMatcher : public ComparisonBase <LtMatcher<Rhs>, Rhs, std::less<>> {
743+ class [[nodiscard]] LtMatcher
744+ : public ComparisonBase<LtMatcher<Rhs>, Rhs, std::less<>> {
743745 public:
744746 explicit LtMatcher (const Rhs& rhs)
745747 : ComparisonBase<LtMatcher<Rhs>, Rhs, std::less<>>(rhs) {}
746748 static const char * Desc () { return " is <" ; }
747749 static const char * NegatedDesc () { return " isn't <" ; }
748750};
749751template <typename Rhs>
750- class GtMatcher : public ComparisonBase <GtMatcher<Rhs>, Rhs, std::greater<>> {
752+ class [[nodiscard]] GtMatcher
753+ : public ComparisonBase<GtMatcher<Rhs>, Rhs, std::greater<>> {
751754 public:
752755 explicit GtMatcher (const Rhs& rhs)
753756 : ComparisonBase<GtMatcher<Rhs>, Rhs, std::greater<>>(rhs) {}
754757 static const char * Desc () { return " is >" ; }
755758 static const char * NegatedDesc () { return " isn't >" ; }
756759};
757760template <typename Rhs>
758- class LeMatcher
761+ class [[nodiscard]] LeMatcher
759762 : public ComparisonBase<LeMatcher<Rhs>, Rhs, std::less_equal<>> {
760763 public:
761764 explicit LeMatcher (const Rhs& rhs)
@@ -764,7 +767,7 @@ class LeMatcher
764767 static const char * NegatedDesc () { return " isn't <=" ; }
765768};
766769template <typename Rhs>
767- class GeMatcher
770+ class [[nodiscard]] GeMatcher
768771 : public ComparisonBase<GeMatcher<Rhs>, Rhs, std::greater_equal<>> {
769772 public:
770773 explicit GeMatcher (const Rhs& rhs)
@@ -776,7 +779,7 @@ class GeMatcher
776779// Same as `EqMatcher<Rhs>`, except that the `rhs` is stored as `StoredRhs` and
777780// must be implicitly convertible to `Rhs`.
778781template <typename Rhs, typename StoredRhs>
779- class ImplicitCastEqMatcher {
782+ class [[nodiscard]] ImplicitCastEqMatcher {
780783 public:
781784 explicit ImplicitCastEqMatcher (const StoredRhs& rhs) : stored_rhs_ (rhs) {}
782785
@@ -809,7 +812,7 @@ using StringLike = T;
809812// Implements polymorphic matchers MatchesRegex(regex) and
810813// ContainsRegex(regex), which can be used as a Matcher<T> as long as
811814// T can be converted to a string.
812- class MatchesRegexMatcher {
815+ class [[nodiscard]] MatchesRegexMatcher {
813816 public:
814817 MatchesRegexMatcher (const RE* regex, bool full_match)
815818 : regex_ (regex), full_match_ (full_match) {}
0 commit comments