aboutsummaryrefslogtreecommitdiff
path: root/googletest
diff options
context:
space:
mode:
Diffstat (limited to 'googletest')
-rw-r--r--googletest/include/gtest/gtest-assertion-result.h2
-rw-r--r--googletest/include/gtest/gtest-death-test.h6
-rw-r--r--googletest/include/gtest/gtest-matchers.h49
-rw-r--r--googletest/include/gtest/gtest-printers.h52
-rw-r--r--googletest/include/gtest/gtest-spi.h4
-rw-r--r--googletest/include/gtest/gtest-test-part.h8
-rw-r--r--googletest/include/gtest/gtest-typed-test.h4
-rw-r--r--googletest/include/gtest/gtest.h43
-rw-r--r--googletest/include/gtest/internal/gtest-death-test-internal.h22
-rw-r--r--googletest/include/gtest/internal/gtest-filepath.h2
-rw-r--r--googletest/include/gtest/internal/gtest-internal.h41
-rw-r--r--googletest/include/gtest/internal/gtest-param-util.h43
-rw-r--r--googletest/include/gtest/internal/gtest-port.h56
-rw-r--r--googletest/include/gtest/internal/gtest-string.h4
14 files changed, 173 insertions, 163 deletions
diff --git a/googletest/include/gtest/gtest-assertion-result.h b/googletest/include/gtest/gtest-assertion-result.h
index 954e7c4..52a6d62 100644
--- a/googletest/include/gtest/gtest-assertion-result.h
+++ b/googletest/include/gtest/gtest-assertion-result.h
@@ -137,7 +137,7 @@ namespace testing {
class [[nodiscard]] AssertionResult;
#endif // !SWIG
-class GTEST_API_ AssertionResult {
+class GTEST_API_ [[nodiscard]] AssertionResult {
public:
// Copy constructor.
// Used in EXPECT_TRUE/FALSE(assertion_result).
diff --git a/googletest/include/gtest/gtest-death-test.h b/googletest/include/gtest/gtest-death-test.h
index 3c61909..afd7b3a 100644
--- a/googletest/include/gtest/gtest-death-test.h
+++ b/googletest/include/gtest/gtest-death-test.h
@@ -192,7 +192,7 @@ GTEST_API_ bool InDeathTestChild();
// Two predicate classes that can be used in {ASSERT,EXPECT}_EXIT*:
// Tests that an exit code describes a normal exit with a given exit code.
-class GTEST_API_ ExitedWithCode {
+class GTEST_API_ [[nodiscard]] ExitedWithCode {
public:
explicit ExitedWithCode(int exit_code);
ExitedWithCode(const ExitedWithCode&) = default;
@@ -206,7 +206,7 @@ class GTEST_API_ ExitedWithCode {
#if !defined(GTEST_OS_WINDOWS) && !defined(GTEST_OS_FUCHSIA)
// Tests that an exit code describes an exit due to termination by a
// given signal.
-class GTEST_API_ KilledBySignal {
+class GTEST_API_ [[nodiscard]] KilledBySignal {
public:
explicit KilledBySignal(int signum);
bool operator()(int exit_status) const;
@@ -317,7 +317,7 @@ class GTEST_API_ KilledBySignal {
GTEST_LOG_(WARNING) << "Death tests are not supported on this platform.\n" \
<< "Statement '" #statement "' cannot be verified."; \
} else if (::testing::internal::AlwaysFalse()) { \
- ::testing::internal::MakeDeathTestMatcher(regex_or_matcher); \
+ (void)::testing::internal::MakeDeathTestMatcher(regex_or_matcher); \
GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
terminator; \
} else \
diff --git a/googletest/include/gtest/gtest-matchers.h b/googletest/include/gtest/gtest-matchers.h
index bd8dfe9..08ffbeb 100644
--- a/googletest/include/gtest/gtest-matchers.h
+++ b/googletest/include/gtest/gtest-matchers.h
@@ -75,7 +75,7 @@ namespace testing {
// 2. a factory function that creates a Matcher<T> object from a
// FooMatcherMatcher.
-class MatchResultListener {
+class [[nodiscard]] MatchResultListener {
public:
// Creates a listener object with the given underlying ostream. The
// listener does not own the ostream, and does not dereference it
@@ -111,7 +111,7 @@ inline MatchResultListener::~MatchResultListener() = default;
// An instance of a subclass of this knows how to describe itself as a
// matcher.
-class GTEST_API_ MatcherDescriberInterface {
+class GTEST_API_ [[nodiscard]] MatcherDescriberInterface {
public:
virtual ~MatcherDescriberInterface() = default;
@@ -137,7 +137,7 @@ class GTEST_API_ MatcherDescriberInterface {
// The implementation of a matcher.
template <typename T>
-class MatcherInterface : public MatcherDescriberInterface {
+class [[nodiscard]] MatcherInterface : public MatcherDescriberInterface {
public:
// Returns true if and only if the matcher matches x; also explains the
// match result to 'listener' if necessary (see the next paragraph), in
@@ -180,7 +180,7 @@ class MatcherInterface : public MatcherDescriberInterface {
namespace internal {
// A match result listener that ignores the explanation.
-class DummyMatchResultListener : public MatchResultListener {
+class [[nodiscard]] DummyMatchResultListener : public MatchResultListener {
public:
DummyMatchResultListener() : MatchResultListener(nullptr) {}
@@ -192,7 +192,7 @@ class DummyMatchResultListener : public MatchResultListener {
// A match result listener that forwards the explanation to a given
// ostream. The difference between this and MatchResultListener is
// that the former is concrete.
-class StreamMatchResultListener : public MatchResultListener {
+class [[nodiscard]] StreamMatchResultListener : public MatchResultListener {
public:
explicit StreamMatchResultListener(::std::ostream* os)
: MatchResultListener(os) {}
@@ -225,7 +225,7 @@ struct SharedPayload : SharedPayloadBase {
// from it. We put functionalities common to all Matcher<T>
// specializations here to avoid code duplication.
template <typename T>
-class MatcherBase : private MatcherDescriberInterface {
+class [[nodiscard]] MatcherBase : private MatcherDescriberInterface {
public:
// Returns true if and only if the matcher matches x; also explains the
// match result to 'listener'.
@@ -460,7 +460,7 @@ class MatcherBase : private MatcherDescriberInterface {
// implementation of Matcher<T> is just a std::shared_ptr to const
// MatcherInterface<T>. Don't inherit from Matcher!
template <typename T>
-class Matcher : public internal::MatcherBase<T> {
+class [[nodiscard]] Matcher : public internal::MatcherBase<T> {
public:
// Constructs a null matcher. Needed for storing Matcher objects in STL
// containers. A default-constructed matcher is not yet initialized. You
@@ -491,8 +491,8 @@ class Matcher : public internal::MatcherBase<T> {
// instead of Eq(str) and "foo" instead of Eq("foo") when a std::string
// matcher is expected.
template <>
-class GTEST_API_ Matcher<const std::string&>
- : public internal::MatcherBase<const std::string&> {
+class GTEST_API_ [[nodiscard]]
+Matcher<const std::string&> : public internal::MatcherBase<const std::string&> {
public:
Matcher() = default;
@@ -513,8 +513,8 @@ class GTEST_API_ Matcher<const std::string&>
};
template <>
-class GTEST_API_ Matcher<std::string>
- : public internal::MatcherBase<std::string> {
+class GTEST_API_ [[nodiscard]]
+Matcher<std::string> : public internal::MatcherBase<std::string> {
public:
Matcher() = default;
@@ -541,7 +541,7 @@ class GTEST_API_ Matcher<std::string>
// instead of Eq(str) and "foo" instead of Eq("foo") when a absl::string_view
// matcher is expected.
template <>
-class GTEST_API_ Matcher<const internal::StringView&>
+class GTEST_API_ [[nodiscard]] Matcher<const internal::StringView&>
: public internal::MatcherBase<const internal::StringView&> {
public:
Matcher() = default;
@@ -567,7 +567,7 @@ class GTEST_API_ Matcher<const internal::StringView&>
};
template <>
-class GTEST_API_ Matcher<internal::StringView>
+class GTEST_API_ [[nodiscard]] Matcher<internal::StringView>
: public internal::MatcherBase<internal::StringView> {
public:
Matcher() = default;
@@ -614,7 +614,7 @@ std::ostream& operator<<(std::ostream& os, const Matcher<T>& matcher) {
//
// See the definition of NotNull() for a complete example.
template <class Impl>
-class PolymorphicMatcher {
+class [[nodiscard]] PolymorphicMatcher {
public:
explicit PolymorphicMatcher(const Impl& an_impl) : impl_(an_impl) {}
@@ -689,7 +689,7 @@ namespace internal {
// The following template definition assumes that the Rhs parameter is
// a "bare" type (i.e. neither 'const T' nor 'T&').
template <typename D, typename Rhs, typename Op>
-class ComparisonBase {
+class [[nodiscard]] ComparisonBase {
public:
explicit ComparisonBase(const Rhs& rhs) : rhs_(rhs) {}
@@ -722,7 +722,8 @@ class ComparisonBase {
};
template <typename Rhs>
-class EqMatcher : public ComparisonBase<EqMatcher<Rhs>, Rhs, std::equal_to<>> {
+class [[nodiscard]] EqMatcher
+ : public ComparisonBase<EqMatcher<Rhs>, Rhs, std::equal_to<>> {
public:
explicit EqMatcher(const Rhs& rhs)
: ComparisonBase<EqMatcher<Rhs>, Rhs, std::equal_to<>>(rhs) {}
@@ -730,7 +731,7 @@ class EqMatcher : public ComparisonBase<EqMatcher<Rhs>, Rhs, std::equal_to<>> {
static const char* NegatedDesc() { return "isn't equal to"; }
};
template <typename Rhs>
-class NeMatcher
+class [[nodiscard]] NeMatcher
: public ComparisonBase<NeMatcher<Rhs>, Rhs, std::not_equal_to<>> {
public:
explicit NeMatcher(const Rhs& rhs)
@@ -739,7 +740,8 @@ class NeMatcher
static const char* NegatedDesc() { return "is equal to"; }
};
template <typename Rhs>
-class LtMatcher : public ComparisonBase<LtMatcher<Rhs>, Rhs, std::less<>> {
+class [[nodiscard]] LtMatcher
+ : public ComparisonBase<LtMatcher<Rhs>, Rhs, std::less<>> {
public:
explicit LtMatcher(const Rhs& rhs)
: ComparisonBase<LtMatcher<Rhs>, Rhs, std::less<>>(rhs) {}
@@ -747,7 +749,8 @@ class LtMatcher : public ComparisonBase<LtMatcher<Rhs>, Rhs, std::less<>> {
static const char* NegatedDesc() { return "isn't <"; }
};
template <typename Rhs>
-class GtMatcher : public ComparisonBase<GtMatcher<Rhs>, Rhs, std::greater<>> {
+class [[nodiscard]] GtMatcher
+ : public ComparisonBase<GtMatcher<Rhs>, Rhs, std::greater<>> {
public:
explicit GtMatcher(const Rhs& rhs)
: ComparisonBase<GtMatcher<Rhs>, Rhs, std::greater<>>(rhs) {}
@@ -755,7 +758,7 @@ class GtMatcher : public ComparisonBase<GtMatcher<Rhs>, Rhs, std::greater<>> {
static const char* NegatedDesc() { return "isn't >"; }
};
template <typename Rhs>
-class LeMatcher
+class [[nodiscard]] LeMatcher
: public ComparisonBase<LeMatcher<Rhs>, Rhs, std::less_equal<>> {
public:
explicit LeMatcher(const Rhs& rhs)
@@ -764,7 +767,7 @@ class LeMatcher
static const char* NegatedDesc() { return "isn't <="; }
};
template <typename Rhs>
-class GeMatcher
+class [[nodiscard]] GeMatcher
: public ComparisonBase<GeMatcher<Rhs>, Rhs, std::greater_equal<>> {
public:
explicit GeMatcher(const Rhs& rhs)
@@ -776,7 +779,7 @@ class GeMatcher
// Same as `EqMatcher<Rhs>`, except that the `rhs` is stored as `StoredRhs` and
// must be implicitly convertible to `Rhs`.
template <typename Rhs, typename StoredRhs>
-class ImplicitCastEqMatcher {
+class [[nodiscard]] ImplicitCastEqMatcher {
public:
explicit ImplicitCastEqMatcher(const StoredRhs& rhs) : stored_rhs_(rhs) {}
@@ -809,7 +812,7 @@ using StringLike = T;
// Implements polymorphic matchers MatchesRegex(regex) and
// ContainsRegex(regex), which can be used as a Matcher<T> as long as
// T can be converted to a string.
-class MatchesRegexMatcher {
+class [[nodiscard]] MatchesRegexMatcher {
public:
MatchesRegexMatcher(const RE* regex, bool full_match)
: regex_(regex), full_match_(full_match) {}
diff --git a/googletest/include/gtest/gtest-printers.h b/googletest/include/gtest/gtest-printers.h
index 048c32d..d1704bb 100644
--- a/googletest/include/gtest/gtest-printers.h
+++ b/googletest/include/gtest/gtest-printers.h
@@ -382,7 +382,7 @@ void PrintWithFallback(const T& value, ::std::ostream* os) {
// The default case.
template <typename ToPrint, typename OtherOperand>
-class FormatForComparison {
+class [[nodiscard]] FormatForComparison {
public:
static ::std::string Format(const ToPrint& value) {
return ::testing::PrintToString(value);
@@ -391,7 +391,7 @@ class FormatForComparison {
// Array.
template <typename ToPrint, size_t N, typename OtherOperand>
-class FormatForComparison<ToPrint[N], OtherOperand> {
+class [[nodiscard]] FormatForComparison<ToPrint[N], OtherOperand> {
public:
static ::std::string Format(const ToPrint* value) {
return FormatForComparison<const ToPrint*, OtherOperand>::Format(value);
@@ -477,7 +477,7 @@ std::string FormatForComparisonFailureMessage(const T1& value,
// function template), as we need to partially specialize it for
// reference types, which cannot be done with function templates.
template <typename T>
-class UniversalPrinter;
+class [[nodiscard]] UniversalPrinter;
// Prints the given value using the << operator if it has one;
// otherwise prints the bytes in it. This is what
@@ -889,7 +889,7 @@ void PrintTo(const ::std::pair<T1, T2>& value, ::std::ostream* os) {
// Implements printing a non-reference type T by letting the compiler
// pick the right overload of PrintTo() for T.
template <typename T>
-class UniversalPrinter {
+class [[nodiscard]] UniversalPrinter {
public:
// MSVC warns about adding const to a function type, so we want to
// disable the warning.
@@ -915,11 +915,11 @@ class UniversalPrinter {
// Remove any const-qualifiers before passing a type to UniversalPrinter.
template <typename T>
-class UniversalPrinter<const T> : public UniversalPrinter<T> {};
+class [[nodiscard]] UniversalPrinter<const T> : public UniversalPrinter<T> {};
// Printer for std::any
template <>
-class UniversalPrinter<std::any> {
+class [[nodiscard]] UniversalPrinter<std::any> {
public:
static void Print(const std::any& value, ::std::ostream* os) {
if (value.has_value()) {
@@ -942,7 +942,7 @@ class UniversalPrinter<std::any> {
// Printer for std::optional
template <typename T>
-class UniversalPrinter<std::optional<T>> {
+class [[nodiscard]] UniversalPrinter<std::optional<T>> {
public:
static void Print(const std::optional<T>& value, ::std::ostream* os) {
*os << '(';
@@ -956,14 +956,14 @@ class UniversalPrinter<std::optional<T>> {
};
template <>
-class UniversalPrinter<std::nullopt_t> {
+class [[nodiscard]] UniversalPrinter<std::nullopt_t> {
public:
static void Print(std::nullopt_t, ::std::ostream* os) { *os << "(nullopt)"; }
};
// Printer for std::variant
template <typename... T>
-class UniversalPrinter<std::variant<T...>> {
+class [[nodiscard]] UniversalPrinter<std::variant<T...>> {
public:
static void Print(const std::variant<T...>& value, ::std::ostream* os) {
*os << '(';
@@ -1031,7 +1031,7 @@ GTEST_API_ void UniversalPrintArray(const wchar_t* begin, size_t len,
// Implements printing an array type T[N].
template <typename T, size_t N>
-class UniversalPrinter<T[N]> {
+class [[nodiscard]] UniversalPrinter<T[N]> {
public:
// Prints the given array, omitting some elements when there are too
// many.
@@ -1042,7 +1042,7 @@ class UniversalPrinter<T[N]> {
// Implements printing a reference type T&.
template <typename T>
-class UniversalPrinter<T&> {
+class [[nodiscard]] UniversalPrinter<T&> {
public:
// MSVC warns about adding const to a function type, so we want to
// disable the warning.
@@ -1065,35 +1065,35 @@ class UniversalPrinter<T&> {
// NUL-terminated string (but not the pointer) is printed.
template <typename T>
-class UniversalTersePrinter {
+class [[nodiscard]] UniversalTersePrinter {
public:
static void Print(const T& value, ::std::ostream* os) {
UniversalPrint(value, os);
}
};
template <typename T>
-class UniversalTersePrinter<T&> {
+class [[nodiscard]] UniversalTersePrinter<T&> {
public:
static void Print(const T& value, ::std::ostream* os) {
UniversalPrint(value, os);
}
};
template <typename T>
-class UniversalTersePrinter<std::reference_wrapper<T>> {
+class [[nodiscard]] UniversalTersePrinter<std::reference_wrapper<T>> {
public:
static void Print(std::reference_wrapper<T> value, ::std::ostream* os) {
UniversalTersePrinter<T>::Print(value.get(), os);
}
};
template <typename T, size_t N>
-class UniversalTersePrinter<T[N]> {
+class [[nodiscard]] UniversalTersePrinter<T[N]> {
public:
static void Print(const T (&value)[N], ::std::ostream* os) {
UniversalPrinter<T[N]>::Print(value, os);
}
};
template <>
-class UniversalTersePrinter<const char*> {
+class [[nodiscard]] UniversalTersePrinter<const char*> {
public:
static void Print(const char* str, ::std::ostream* os) {
if (str == nullptr) {
@@ -1104,12 +1104,12 @@ class UniversalTersePrinter<const char*> {
}
};
template <>
-class UniversalTersePrinter<char*> : public UniversalTersePrinter<const char*> {
-};
+class [[nodiscard]]
+UniversalTersePrinter<char*> : public UniversalTersePrinter<const char*> {};
#ifdef __cpp_lib_char8_t
template <>
-class UniversalTersePrinter<const char8_t*> {
+class [[nodiscard]] UniversalTersePrinter<const char8_t*> {
public:
static void Print(const char8_t* str, ::std::ostream* os) {
if (str == nullptr) {
@@ -1120,12 +1120,12 @@ class UniversalTersePrinter<const char8_t*> {
}
};
template <>
-class UniversalTersePrinter<char8_t*>
+class [[nodiscard]] UniversalTersePrinter<char8_t*>
: public UniversalTersePrinter<const char8_t*> {};
#endif
template <>
-class UniversalTersePrinter<const char16_t*> {
+class [[nodiscard]] UniversalTersePrinter<const char16_t*> {
public:
static void Print(const char16_t* str, ::std::ostream* os) {
if (str == nullptr) {
@@ -1136,11 +1136,11 @@ class UniversalTersePrinter<const char16_t*> {
}
};
template <>
-class UniversalTersePrinter<char16_t*>
+class [[nodiscard]] UniversalTersePrinter<char16_t*>
: public UniversalTersePrinter<const char16_t*> {};
template <>
-class UniversalTersePrinter<const char32_t*> {
+class [[nodiscard]] UniversalTersePrinter<const char32_t*> {
public:
static void Print(const char32_t* str, ::std::ostream* os) {
if (str == nullptr) {
@@ -1151,12 +1151,12 @@ class UniversalTersePrinter<const char32_t*> {
}
};
template <>
-class UniversalTersePrinter<char32_t*>
+class [[nodiscard]] UniversalTersePrinter<char32_t*>
: public UniversalTersePrinter<const char32_t*> {};
#if GTEST_HAS_STD_WSTRING
template <>
-class UniversalTersePrinter<const wchar_t*> {
+class [[nodiscard]] UniversalTersePrinter<const wchar_t*> {
public:
static void Print(const wchar_t* str, ::std::ostream* os) {
if (str == nullptr) {
@@ -1169,7 +1169,7 @@ class UniversalTersePrinter<const wchar_t*> {
#endif
template <>
-class UniversalTersePrinter<wchar_t*> {
+class [[nodiscard]] UniversalTersePrinter<wchar_t*> {
public:
static void Print(wchar_t* str, ::std::ostream* os) {
UniversalTersePrinter<const wchar_t*>::Print(str, os);
diff --git a/googletest/include/gtest/gtest-spi.h b/googletest/include/gtest/gtest-spi.h
index c0613b6..27c2d66 100644
--- a/googletest/include/gtest/gtest-spi.h
+++ b/googletest/include/gtest/gtest-spi.h
@@ -51,7 +51,7 @@ namespace testing {
// generated in the same thread that created this object or it can intercept
// all generated failures. The scope of this mock object can be controlled with
// the second argument to the two arguments constructor.
-class GTEST_API_ ScopedFakeTestPartResultReporter
+class GTEST_API_ [[nodiscard]] ScopedFakeTestPartResultReporter
: public TestPartResultReporterInterface {
public:
// The two possible mocking modes of this object.
@@ -100,7 +100,7 @@ namespace internal {
// TestPartResultArray contains exactly one failure that has the given
// type and contains the given substring. If that's not the case, a
// non-fatal failure will be generated.
-class GTEST_API_ SingleFailureChecker {
+class GTEST_API_ [[nodiscard]] SingleFailureChecker {
public:
// The constructor remembers the arguments.
SingleFailureChecker(const TestPartResultArray* results,
diff --git a/googletest/include/gtest/gtest-test-part.h b/googletest/include/gtest/gtest-test-part.h
index 41c8a9a..90380a9 100644
--- a/googletest/include/gtest/gtest-test-part.h
+++ b/googletest/include/gtest/gtest-test-part.h
@@ -51,7 +51,7 @@ namespace testing {
// assertion or an explicit FAIL(), ADD_FAILURE(), or SUCCESS()).
//
// Don't inherit from TestPartResult as its destructor is not virtual.
-class GTEST_API_ TestPartResult {
+class GTEST_API_ [[nodiscard]] TestPartResult {
public:
// The possible outcomes of a test part (i.e. an assertion or an
// explicit SUCCEED(), FAIL(), or ADD_FAILURE()).
@@ -131,7 +131,7 @@ std::ostream& operator<<(std::ostream& os, const TestPartResult& result);
//
// Don't inherit from TestPartResultArray as its destructor is not
// virtual.
-class GTEST_API_ TestPartResultArray {
+class GTEST_API_ [[nodiscard]] TestPartResultArray {
public:
TestPartResultArray() = default;
@@ -152,7 +152,7 @@ class GTEST_API_ TestPartResultArray {
};
// This interface knows how to report a test part result.
-class GTEST_API_ TestPartResultReporterInterface {
+class GTEST_API_ [[nodiscard]] TestPartResultReporterInterface {
public:
virtual ~TestPartResultReporterInterface() = default;
@@ -167,7 +167,7 @@ namespace internal {
// reported, it only delegates the reporting to the former result reporter.
// The original result reporter is restored in the destructor.
// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
-class GTEST_API_ HasNewFatalFailureHelper
+class GTEST_API_ [[nodiscard]] HasNewFatalFailureHelper
: public TestPartResultReporterInterface {
public:
HasNewFatalFailureHelper();
diff --git a/googletest/include/gtest/gtest-typed-test.h b/googletest/include/gtest/gtest-typed-test.h
index ae24f94..8575a41 100644
--- a/googletest/include/gtest/gtest-typed-test.h
+++ b/googletest/include/gtest/gtest-typed-test.h
@@ -45,7 +45,7 @@
// First, define a fixture class template. It should be parameterized
// by a type. Remember to derive it from testing::Test.
template <typename T>
-class FooTest : public testing::Test {
+class [[nodiscard]] FooTest : public testing::Test {
public:
...
using List = ::std::list<T>;
@@ -123,7 +123,7 @@ TYPED_TEST(FooTest, HasPropertyA) { ... }
// First, define a fixture class template. It should be parameterized
// by a type. Remember to derive it from testing::Test.
template <typename T>
-class FooTest : public testing::Test {
+class [[nodiscard]] FooTest : public testing::Test {
...
};
diff --git a/googletest/include/gtest/gtest.h b/googletest/include/gtest/gtest.h
index 69994ee..b636853 100644
--- a/googletest/include/gtest/gtest.h
+++ b/googletest/include/gtest/gtest.h
@@ -193,7 +193,7 @@ std::set<std::string>* GetIgnoredParameterizedTestSuites();
// A base class that prevents subclasses from being copyable.
// We do this instead of using '= delete' so as to avoid triggering warnings
// inside user code regarding any of our declarations.
-class GTestNonCopyable {
+class [[nodiscard]] GTestNonCopyable {
public:
GTestNonCopyable() = default;
GTestNonCopyable(const GTestNonCopyable&) = delete;
@@ -206,15 +206,15 @@ class GTestNonCopyable {
// The friend relationship of some of these classes is cyclic.
// If we don't forward declare them the compiler might confuse the classes
// in friendship clauses with same named classes on the scope.
-class Test;
-class TestSuite;
+class [[nodiscard]] Test;
+class [[nodiscard]] TestSuite;
// Old API is still available but deprecated
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
using TestCase = TestSuite;
#endif
-class TestInfo;
-class UnitTest;
+class [[nodiscard]] TestInfo;
+class [[nodiscard]] UnitTest;
// The abstract class that all tests inherit from.
//
@@ -239,7 +239,7 @@ class UnitTest;
// TEST_F(FooTest, Baz) { ... }
//
// Test is not copyable.
-class GTEST_API_ Test {
+class GTEST_API_ [[nodiscard]] Test {
public:
friend class TestInfo;
@@ -366,7 +366,7 @@ typedef internal::TimeInMillis TimeInMillis;
// output as a key/value string pair.
//
// Don't inherit from TestProperty as its destructor is not virtual.
-class TestProperty {
+class [[nodiscard]] TestProperty {
public:
// C'tor. TestProperty does NOT have a default constructor.
// Always use this constructor (with parameters) to create a
@@ -396,7 +396,7 @@ class TestProperty {
// the Test.
//
// TestResult is not copyable.
-class GTEST_API_ TestResult {
+class GTEST_API_ [[nodiscard]] TestResult {
public:
// Creates an empty TestResult.
TestResult();
@@ -530,7 +530,7 @@ class GTEST_API_ TestResult {
// The constructor of TestInfo registers itself with the UnitTest
// singleton such that the RUN_ALL_TESTS() macro knows which tests to
// run.
-class GTEST_API_ TestInfo {
+class GTEST_API_ [[nodiscard]] TestInfo {
public:
// Destructs a TestInfo object. This function is not virtual, so
// don't inherit from TestInfo.
@@ -669,7 +669,7 @@ class GTEST_API_ TestInfo {
// A test suite, which consists of a vector of TestInfos.
//
// TestSuite is not copyable.
-class GTEST_API_ TestSuite {
+class GTEST_API_ [[nodiscard]] TestSuite {
public:
// Creates a TestSuite with the given name.
//
@@ -890,7 +890,7 @@ class GTEST_API_ TestSuite {
// available.
// 2. You cannot use ASSERT_* directly in a constructor or
// destructor.
-class Environment {
+class [[nodiscard]] Environment {
public:
// The d'tor is virtual as we need to subclass Environment.
virtual ~Environment() = default;
@@ -911,7 +911,7 @@ class Environment {
#if GTEST_HAS_EXCEPTIONS
// Exception which can be thrown from TestEventListener::OnTestPartResult.
-class GTEST_API_ AssertionException
+class GTEST_API_ [[nodiscard]] AssertionException
: public internal::GoogleTestFailureException {
public:
explicit AssertionException(const TestPartResult& result)
@@ -922,7 +922,7 @@ class GTEST_API_ AssertionException
// The interface for tracing execution of tests. The methods are organized in
// the order the corresponding events are fired.
-class TestEventListener {
+class [[nodiscard]] TestEventListener {
public:
virtual ~TestEventListener() = default;
@@ -989,7 +989,7 @@ class TestEventListener {
// the methods they override will not be caught during the build. For
// comments about each method please see the definition of TestEventListener
// above.
-class EmptyTestEventListener : public TestEventListener {
+class [[nodiscard]] EmptyTestEventListener : public TestEventListener {
public:
void OnTestProgramStart(const UnitTest& /*unit_test*/) override {}
void OnTestIterationStart(const UnitTest& /*unit_test*/,
@@ -1019,7 +1019,7 @@ class EmptyTestEventListener : public TestEventListener {
};
// TestEventListeners lets users add listeners to track events in Google Test.
-class GTEST_API_ TestEventListeners {
+class GTEST_API_ [[nodiscard]] TestEventListeners {
public:
TestEventListeners();
~TestEventListeners();
@@ -1110,7 +1110,7 @@ class GTEST_API_ TestEventListeners {
//
// This class is thread-safe as long as the methods are called
// according to their specification.
-class GTEST_API_ UnitTest {
+class GTEST_API_ [[nodiscard]] UnitTest {
public:
// Gets the singleton UnitTest object. The first time this method
// is called, a UnitTest object is constructed and returned.
@@ -1398,7 +1398,7 @@ AssertionResult CmpHelperEQ(const char* lhs_expression,
return CmpHelperEQFailure(lhs_expression, rhs_expression, lhs, rhs);
}
-class EqHelper {
+class [[nodiscard]] EqHelper {
public:
// This templatized version is for the general case.
template <
@@ -1614,7 +1614,7 @@ using GoogleTest_NotSupported_OnFunctionReturningNonVoid = void;
// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
// A class that enables one to stream messages to assertion macros
-class GTEST_API_ AssertHelper {
+class GTEST_API_ [[nodiscard]] AssertHelper {
public:
// Constructor.
AssertHelper(TestPartResult::Type type, const char* file, int line,
@@ -1689,7 +1689,7 @@ class GTEST_API_ AssertHelper {
// INSTANTIATE_TEST_SUITE_P(OneToTenRange, FooTest, ::testing::Range(1, 10));
template <typename T>
-class WithParamInterface {
+class [[nodiscard]] WithParamInterface {
public:
typedef T ParamType;
virtual ~WithParamInterface() = default;
@@ -1723,7 +1723,8 @@ const T* WithParamInterface<T>::parameter_ = nullptr;
// WithParamInterface, and can just inherit from ::testing::TestWithParam.
template <typename T>
-class TestWithParam : public Test, public WithParamInterface<T> {};
+class [[nodiscard]] TestWithParam : public Test,
+ public WithParamInterface<T> {};
// Macros for indicating success/failure in test code.
@@ -2071,7 +2072,7 @@ GTEST_API_ AssertionResult DoubleLE(const char* expr1, const char* expr2,
// Example:
// testing::ScopedTrace trace("file.cc", 123, "message");
//
-class GTEST_API_ ScopedTrace {
+class GTEST_API_ [[nodiscard]] ScopedTrace {
public:
// The c'tor pushes the given source file location and message onto
// a trace stack maintained by Google Test.
diff --git a/googletest/include/gtest/internal/gtest-death-test-internal.h b/googletest/include/gtest/internal/gtest-death-test-internal.h
index b363259..6013a57 100644
--- a/googletest/include/gtest/internal/gtest-death-test-internal.h
+++ b/googletest/include/gtest/internal/gtest-death-test-internal.h
@@ -96,7 +96,7 @@ GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \
// by wait(2)
// exit code: The integer code passed to exit(3), _Exit(2), or
// returned from main()
-class GTEST_API_ DeathTest {
+class GTEST_API_ [[nodiscard]] DeathTest {
public:
// Create returns false if there was an error determining the
// appropriate action to take for the current death test; for example,
@@ -172,7 +172,7 @@ class GTEST_API_ DeathTest {
GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251
// Factory interface for death tests. May be mocked out for testing.
-class DeathTestFactory {
+class [[nodiscard]] DeathTestFactory {
public:
virtual ~DeathTestFactory() = default;
virtual bool Create(const char* statement,
@@ -181,7 +181,7 @@ class DeathTestFactory {
};
// A concrete DeathTestFactory implementation for normal use.
-class DefaultDeathTestFactory : public DeathTestFactory {
+class [[nodiscard]] DefaultDeathTestFactory : public DeathTestFactory {
public:
bool Create(const char* statement, Matcher<const std::string&> matcher,
const char* file, int line, DeathTest** test) override;
@@ -256,19 +256,19 @@ GTEST_API_ bool ExitedUnsuccessfully(int exit_status);
// must accept a streamed message even though the message is never printed.
// The regex object is not evaluated, but it is used to prevent "unused"
// warnings and to avoid an expression that doesn't compile in debug mode.
-#define GTEST_EXECUTE_STATEMENT_(statement, regex_or_matcher) \
- GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
- if (::testing::internal::AlwaysTrue()) { \
- GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
- } else if (!::testing::internal::AlwaysTrue()) { \
- ::testing::internal::MakeDeathTestMatcher(regex_or_matcher); \
- } else \
+#define GTEST_EXECUTE_STATEMENT_(statement, regex_or_matcher) \
+ GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
+ if (::testing::internal::AlwaysTrue()) { \
+ GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
+ } else if (!::testing::internal::AlwaysTrue()) { \
+ (void)::testing::internal::MakeDeathTestMatcher(regex_or_matcher); \
+ } else \
::testing::Message()
// A class representing the parsed contents of the
// --gtest_internal_run_death_test flag, as it existed when
// RUN_ALL_TESTS was called.
-class InternalRunDeathTestFlag {
+class [[nodiscard]] InternalRunDeathTestFlag {
public:
InternalRunDeathTestFlag(const std::string& a_file, int a_line, int an_index,
int a_write_fd)
diff --git a/googletest/include/gtest/internal/gtest-filepath.h b/googletest/include/gtest/internal/gtest-filepath.h
index 6dc47be..4dc00ee 100644
--- a/googletest/include/gtest/internal/gtest-filepath.h
+++ b/googletest/include/gtest/internal/gtest-filepath.h
@@ -67,7 +67,7 @@ namespace internal {
// Names are NOT checked for syntax correctness -- no checking for illegal
// characters, malformed paths, etc.
-class GTEST_API_ FilePath {
+class GTEST_API_ [[nodiscard]] FilePath {
public:
FilePath() : pathname_("") {}
FilePath(const FilePath& rhs) : pathname_(rhs.pathname_) {}
diff --git a/googletest/include/gtest/internal/gtest-internal.h b/googletest/include/gtest/internal/gtest-internal.h
index 808d89b..4379137 100644
--- a/googletest/include/gtest/internal/gtest-internal.h
+++ b/googletest/include/gtest/internal/gtest-internal.h
@@ -95,7 +95,7 @@
#define GTEST_STRINGIFY_(...) GTEST_STRINGIFY_HELPER_(__VA_ARGS__, )
namespace proto2 {
-class MessageLite;
+class [[nodiscard]] MessageLite;
}
namespace testing {
@@ -115,15 +115,15 @@ template <typename T>
namespace internal {
struct TraceInfo; // Information about a trace point.
-class TestInfoImpl; // Opaque implementation of TestInfo
-class UnitTestImpl; // Opaque implementation of UnitTest
+class [[nodiscard]] TestInfoImpl; // Opaque implementation of TestInfo
+class [[nodiscard]] UnitTestImpl; // Opaque implementation of UnitTest
// The text used in failure messages to indicate the start of the
// stack trace.
GTEST_API_ extern const char kStackTraceMarker[];
// An IgnoredValue object can be implicitly constructed from ANY value.
-class IgnoredValue {
+class [[nodiscard]] IgnoredValue {
struct Sink {};
public:
@@ -155,7 +155,8 @@ GTEST_DISABLE_MSC_WARNINGS_PUSH_(
// errors presumably detectable only at run time. Since
// std::runtime_error inherits from std::exception, many testing
// frameworks know how to extract and print the message inside it.
-class GTEST_API_ GoogleTestFailureException : public ::std::runtime_error {
+class GTEST_API_ [[nodiscard]] GoogleTestFailureException
+ : public ::std::runtime_error {
public:
explicit GoogleTestFailureException(const TestPartResult& failure);
};
@@ -242,7 +243,7 @@ GTEST_API_ std::string GetBoolAssertionFailureMessage(
//
// RawType: the raw floating-point type (either float or double)
template <typename RawType>
-class FloatingPoint {
+class [[nodiscard]] FloatingPoint {
public:
// Defines the unsigned integer type that has the same size as the
// floating point number.
@@ -392,7 +393,7 @@ typedef FloatingPoint<double> Double;
typedef const void* TypeId;
template <typename T>
-class TypeIdHelper {
+class [[nodiscard]] TypeIdHelper {
public:
// dummy_ must not have a const type. Otherwise an overly eager
// compiler (e.g. MSVC 7.1 & 8.0) may try to merge
@@ -424,7 +425,7 @@ GTEST_API_ TypeId GetTestTypeId();
// Defines the abstract factory interface that creates instances
// of a Test object.
-class TestFactoryBase {
+class [[nodiscard]] TestFactoryBase {
public:
virtual ~TestFactoryBase() = default;
@@ -443,7 +444,7 @@ class TestFactoryBase {
// This class provides implementation of TestFactoryBase interface.
// It is used in TEST and TEST_F macros.
template <class TestClass>
-class TestFactoryImpl : public TestFactoryBase {
+class [[nodiscard]] TestFactoryImpl : public TestFactoryBase {
public:
Test* CreateTest() override { return new TestClass; }
};
@@ -570,7 +571,7 @@ GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \
/* class A needs to have dll-interface to be used by clients of class B */)
// State of the definition of a type-parameterized test suite.
-class GTEST_API_ TypedTestSuitePState {
+class GTEST_API_ [[nodiscard]] TypedTestSuitePState {
public:
TypedTestSuitePState() : registered_(false) {}
@@ -685,7 +686,7 @@ std::vector<std::string> GenerateNames() {
// Implementation note: The GTEST_TEMPLATE_ macro declares a template
// template parameter. It's defined in gtest-type-util.h.
template <GTEST_TEMPLATE_ Fixture, class TestSel, typename Types>
-class TypeParameterizedTest {
+class [[nodiscard]] TypeParameterizedTest {
public:
// 'index' is the index of the test in the type list 'Types'
// specified in INSTANTIATE_TYPED_TEST_SUITE_P(Prefix, TestSuite,
@@ -723,7 +724,7 @@ class TypeParameterizedTest {
// The base case for the compile time recursion.
template <GTEST_TEMPLATE_ Fixture, class TestSel>
-class TypeParameterizedTest<Fixture, TestSel, internal::None> {
+class [[nodiscard]] TypeParameterizedTest<Fixture, TestSel, internal::None> {
public:
static bool Register(const char* /*prefix*/, CodeLocation,
const char* /*case_name*/, const char* /*test_names*/,
@@ -744,7 +745,7 @@ GTEST_API_ void RegisterTypeParameterizedTestSuiteInstantiation(
// Test. The return value is insignificant - we just need to return
// something such that we can call this function in a namespace scope.
template <GTEST_TEMPLATE_ Fixture, typename Tests, typename Types>
-class TypeParameterizedTestSuite {
+class [[nodiscard]] TypeParameterizedTestSuite {
public:
static bool Register(const char* prefix, CodeLocation code_location,
const TypedTestSuitePState* state, const char* case_name,
@@ -782,7 +783,7 @@ class TypeParameterizedTestSuite {
// The base case for the compile time recursion.
template <GTEST_TEMPLATE_ Fixture, typename Types>
-class TypeParameterizedTestSuite<Fixture, internal::None, Types> {
+class [[nodiscard]] TypeParameterizedTestSuite<Fixture, internal::None, Types> {
public:
static bool Register(const char* /*prefix*/, const CodeLocation&,
const TypedTestSuitePState* /*state*/,
@@ -838,7 +839,7 @@ struct TrueWithString {
// doesn't use global state (and therefore can't interfere with user
// code). Unlike rand_r(), it's portable. An LCG isn't very random,
// but it's good enough for our purposes.
-class GTEST_API_ Random {
+class GTEST_API_ [[nodiscard]] Random {
public:
static const uint32_t kMaxRange = 1u << 31;
@@ -864,7 +865,7 @@ class GTEST_API_ Random {
// that's true if and only if T has methods DebugString() and ShortDebugString()
// that return std::string.
template <typename T>
-class HasDebugStringAndShortDebugString {
+class [[nodiscard]] HasDebugStringAndShortDebugString {
private:
template <typename C>
static auto CheckDebugString(C*) -> typename std::is_same<
@@ -1064,7 +1065,7 @@ struct RelationToSourceCopy {};
// this requirement. Element can be an array type itself (hence
// multi-dimensional arrays are supported).
template <typename Element>
-class NativeArray {
+class [[nodiscard]] NativeArray {
public:
// STL-style container typedefs.
typedef Element value_type;
@@ -1150,7 +1151,7 @@ struct ElemFromList {
struct FlatTupleConstructTag {};
template <typename... T>
-class FlatTuple;
+class [[nodiscard]] FlatTuple;
template <typename Derived, size_t I>
struct FlatTupleElemBase;
@@ -1209,7 +1210,7 @@ struct FlatTupleBase<FlatTuple<T...>, std::index_sequence<Idx...>>
// std::make_index_sequence, on the other hand, it is recursive but with an
// instantiation depth of O(ln(N)).
template <typename... T>
-class FlatTuple
+class [[nodiscard]] FlatTuple
: private FlatTupleBase<FlatTuple<T...>,
std::make_index_sequence<sizeof...(T)>> {
using Indices =
@@ -1317,7 +1318,7 @@ struct tuple_size<testing::internal::FlatTuple<Ts...>>
namespace testing {
namespace internal {
-class NeverThrown {
+class [[nodiscard]] NeverThrown {
public:
const char* what() const noexcept {
return "this exception should never be thrown";
diff --git a/googletest/include/gtest/internal/gtest-param-util.h b/googletest/include/gtest/internal/gtest-param-util.h
index a092a86..7167793 100644
--- a/googletest/include/gtest/internal/gtest-param-util.h
+++ b/googletest/include/gtest/internal/gtest-param-util.h
@@ -90,14 +90,14 @@ GTEST_API_ void ReportInvalidTestSuiteType(const char* test_suite_name,
const CodeLocation& code_location);
template <typename>
-class ParamGeneratorInterface;
+class [[nodiscard]] ParamGeneratorInterface;
template <typename>
-class ParamGenerator;
+class [[nodiscard]] ParamGenerator;
// Interface for iterating over elements provided by an implementation
// of ParamGeneratorInterface<T>.
template <typename T>
-class ParamIteratorInterface {
+class [[nodiscard]] ParamIteratorInterface {
public:
virtual ~ParamIteratorInterface() = default;
// A pointer to the base generator instance.
@@ -127,7 +127,7 @@ class ParamIteratorInterface {
// ParamGeneratorInterface<T>. It wraps ParamIteratorInterface<T>
// and implements the const forward iterator concept.
template <typename T>
-class ParamIterator {
+class [[nodiscard]] ParamIterator {
public:
typedef T value_type;
typedef const T& reference;
@@ -169,7 +169,7 @@ class ParamIterator {
// ParamGeneratorInterface<T> is the binary interface to access generators
// defined in other translation units.
template <typename T>
-class ParamGeneratorInterface {
+class [[nodiscard]] ParamGeneratorInterface {
public:
typedef T ParamType;
@@ -186,7 +186,7 @@ class ParamGeneratorInterface {
// ParamGeneratorInterface<T> instance is shared among all copies
// of the original object. This is possible because that instance is immutable.
template <typename T>
-class ParamGenerator {
+class [[nodiscard]] ParamGenerator {
public:
typedef ParamIterator<T> iterator;
@@ -210,7 +210,7 @@ class ParamGenerator {
// operator<().
// This class is used in the Range() function.
template <typename T, typename IncrementT>
-class RangeGenerator : public ParamGeneratorInterface<T> {
+class [[nodiscard]] RangeGenerator : public ParamGeneratorInterface<T> {
public:
RangeGenerator(T begin, T end, IncrementT step)
: begin_(begin),
@@ -296,7 +296,8 @@ class RangeGenerator : public ParamGeneratorInterface<T> {
// since the source can be located on the stack, and the generator
// is likely to persist beyond that stack frame.
template <typename T>
-class ValuesInIteratorRangeGenerator : public ParamGeneratorInterface<T> {
+class [[nodiscard]] ValuesInIteratorRangeGenerator
+ : public ParamGeneratorInterface<T> {
public:
template <typename ForwardIterator>
ValuesInIteratorRangeGenerator(ForwardIterator begin, ForwardIterator end)
@@ -396,7 +397,7 @@ void TestNotEmpty(const T&) {}
// Stores a parameter value and later creates tests parameterized with that
// value.
template <class TestClass>
-class ParameterizedTestFactory : public TestFactoryBase {
+class [[nodiscard]] ParameterizedTestFactory : public TestFactoryBase {
public:
typedef typename TestClass::ParamType ParamType;
explicit ParameterizedTestFactory(ParamType parameter)
@@ -418,7 +419,7 @@ class ParameterizedTestFactory : public TestFactoryBase {
// TestMetaFactoryBase is a base class for meta-factories that create
// test factories for passing into MakeAndRegisterTestInfo function.
template <class ParamType>
-class TestMetaFactoryBase {
+class [[nodiscard]] TestMetaFactoryBase {
public:
virtual ~TestMetaFactoryBase() = default;
@@ -434,7 +435,7 @@ class TestMetaFactoryBase {
// it for each Test/Parameter value combination. Thus it needs meta factory
// creator class.
template <class TestSuite>
-class TestMetaFactory
+class [[nodiscard]] TestMetaFactory
: public TestMetaFactoryBase<typename TestSuite::ParamType> {
public:
using ParamType = typename TestSuite::ParamType;
@@ -460,7 +461,7 @@ class TestMetaFactory
// in RegisterTests method. The ParameterizeTestSuiteRegistry class holds
// a collection of pointers to the ParameterizedTestSuiteInfo objects
// and calls RegisterTests() on each of them when asked.
-class ParameterizedTestSuiteInfoBase {
+class [[nodiscard]] ParameterizedTestSuiteInfoBase {
public:
virtual ~ParameterizedTestSuiteInfoBase() = default;
@@ -503,7 +504,8 @@ GTEST_API_ void InsertSyntheticTestCase(const std::string& name,
// test suite. It registers tests with all values generated by all
// generators when asked.
template <class TestSuite>
-class ParameterizedTestSuiteInfo : public ParameterizedTestSuiteInfoBase {
+class [[nodiscard]] ParameterizedTestSuiteInfo
+ : public ParameterizedTestSuiteInfoBase {
public:
// ParamType and GeneratorCreationFunc are private types but are required
// for declarations of public methods AddTestPattern() and
@@ -688,7 +690,7 @@ using ParameterizedTestCaseInfo = ParameterizedTestSuiteInfo<TestCase>;
// ParameterizedTestSuiteInfoBase classes accessed by test suite names. TEST_P
// and INSTANTIATE_TEST_SUITE_P macros use it to locate their corresponding
// ParameterizedTestSuiteInfo descriptors.
-class ParameterizedTestSuiteRegistry {
+class [[nodiscard]] ParameterizedTestSuiteRegistry {
public:
ParameterizedTestSuiteRegistry() = default;
~ParameterizedTestSuiteRegistry() {
@@ -762,7 +764,7 @@ class ParameterizedTestSuiteRegistry {
// Keep track of what type-parameterized test suite are defined and
// where as well as which are intatiated. This allows susequently
// identifying suits that are defined but never used.
-class TypeParameterizedTestSuiteRegistry {
+class [[nodiscard]] TypeParameterizedTestSuiteRegistry {
public:
// Add a suite definition
void RegisterTestSuite(const char* test_suite_name,
@@ -801,7 +803,7 @@ namespace internal {
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4100)
template <typename... Ts>
-class ValueArray {
+class [[nodiscard]] ValueArray {
public:
explicit ValueArray(Ts... v) : v_(FlatTupleConstructTag{}, std::move(v)...) {}
@@ -822,7 +824,7 @@ class ValueArray {
GTEST_DISABLE_MSC_WARNINGS_POP_() // 4100
template <typename... T>
-class CartesianProductGenerator
+class [[nodiscard]] CartesianProductGenerator
: public ParamGeneratorInterface<::std::tuple<T...>> {
public:
typedef ::std::tuple<T...> ParamType;
@@ -939,7 +941,7 @@ class CartesianProductGenerator
};
template <class... Gen>
-class CartesianProductHolder {
+class [[nodiscard]] CartesianProductHolder {
public:
CartesianProductHolder(const Gen&... g) : generators_(g...) {}
template <typename... T>
@@ -953,7 +955,8 @@ class CartesianProductHolder {
};
template <typename From, typename To, typename Func>
-class ParamGeneratorConverter : public ParamGeneratorInterface<To> {
+class [[nodiscard]] ParamGeneratorConverter
+ : public ParamGeneratorInterface<To> {
public:
ParamGeneratorConverter(ParamGenerator<From> gen, Func converter) // NOLINT
: generator_(std::move(gen)), converter_(std::move(converter)) {}
@@ -1023,7 +1026,7 @@ class ParamGeneratorConverter : public ParamGeneratorInterface<To> {
template <class GeneratedT,
typename StdFunction =
std::function<const GeneratedT&(const GeneratedT&)>>
-class ParamConverterGenerator {
+class [[nodiscard]] ParamConverterGenerator {
public:
ParamConverterGenerator(ParamGenerator<GeneratedT> g) // NOLINT
: generator_(std::move(g)), converter_(Identity) {}
diff --git a/googletest/include/gtest/internal/gtest-port.h b/googletest/include/gtest/internal/gtest-port.h
index d433f05..f6394a0 100644
--- a/googletest/include/gtest/internal/gtest-port.h
+++ b/googletest/include/gtest/internal/gtest-port.h
@@ -827,6 +827,8 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
#elif defined(GTEST_CREATE_SHARED_LIBRARY) && GTEST_CREATE_SHARED_LIBRARY
#define GTEST_API_ __declspec(dllexport)
#endif
+#elif GTEST_INTERNAL_HAVE_CPP_ATTRIBUTE(gnu::visibility)
+#define GTEST_API_ [[gnu::visibility("default")]]
#elif GTEST_HAVE_ATTRIBUTE_(visibility)
#define GTEST_API_ __attribute__((visibility("default")))
#endif // _MSC_VER
@@ -917,7 +919,7 @@ namespace internal {
// A secret type that Google Test users don't know about. It has no
// accessible constructors on purpose. Therefore it's impossible to create a
// Secret object, which is what we want.
-class Secret {
+class [[nodiscard]] Secret {
Secret(const Secret&) = delete;
};
@@ -932,7 +934,7 @@ GTEST_API_ bool IsTrue(bool condition);
// This is almost `using RE = ::RE2`, except it is copy-constructible, and it
// needs to disambiguate the `std::string`, `absl::string_view`, and `const
// char*` constructors.
-class GTEST_API_ RE {
+class GTEST_API_ [[nodiscard]] RE {
public:
RE(absl::string_view regex) : regex_(regex) {} // NOLINT
RE(const char* regex) : RE(absl::string_view(regex)) {} // NOLINT
@@ -958,7 +960,7 @@ GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \
// A simple C++ wrapper for <regex.h>. It uses the POSIX Extended
// Regular Expression syntax.
-class GTEST_API_ RE {
+class GTEST_API_ [[nodiscard]] RE {
public:
// A copy constructor is required by the Standard to initialize object
// references from r-values.
@@ -1027,7 +1029,7 @@ enum GTestLogSeverity { GTEST_INFO, GTEST_WARNING, GTEST_ERROR, GTEST_FATAL };
// Formats log entry severity, provides a stream object for streaming the
// log message, and terminates the message with a newline when going out of
// scope.
-class GTEST_API_ GTestLog {
+class GTEST_API_ [[nodiscard]] GTestLog {
public:
GTestLog(GTestLogSeverity severity, const char* file, int line);
@@ -1190,7 +1192,7 @@ void ClearInjectableArgvs();
#ifdef GTEST_OS_WINDOWS
// Provides leak-safe Windows kernel handle ownership.
// Used in death tests and in threading support.
-class GTEST_API_ AutoHandle {
+class GTEST_API_ [[nodiscard]] AutoHandle {
public:
// Assume that Win32 HANDLE type is equivalent to void*. Doing so allows us to
// avoid including <windows.h> in this header file. Including <windows.h> is
@@ -1234,7 +1236,7 @@ GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \
// This class is only for testing Google Test's own constructs. Do not
// use it in user tests, either directly or indirectly.
// TODO(b/203539622): Replace unconditionally with absl::Notification.
-class GTEST_API_ Notification {
+class GTEST_API_ [[nodiscard]] Notification {
public:
Notification() : notified_(false) {}
Notification(const Notification&) = delete;
@@ -1273,7 +1275,7 @@ GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251
// in order to call its Run(). Introducing ThreadWithParamBase as a
// non-templated base class for ThreadWithParam allows us to bypass this
// problem.
-class ThreadWithParamBase {
+class [[nodiscard]] ThreadWithParamBase {
public:
virtual ~ThreadWithParamBase() = default;
virtual void Run() = 0;
@@ -1303,7 +1305,7 @@ extern "C" inline void* ThreadFuncWithCLinkage(void* thread) {
// These classes are only for testing Google Test's own constructs. Do
// not use them in user tests, either directly or indirectly.
template <typename T>
-class ThreadWithParam : public ThreadWithParamBase {
+class [[nodiscard]] ThreadWithParam : public ThreadWithParamBase {
public:
typedef void UserThreadFunc(T);
@@ -1369,7 +1371,7 @@ class ThreadWithParam : public ThreadWithParamBase {
// GTEST_DECLARE_STATIC_MUTEX_(g_some_mutex);
//
// (A non-static Mutex is defined/declared in the usual way).
-class GTEST_API_ Mutex {
+class GTEST_API_ [[nodiscard]] Mutex {
public:
enum MutexType { kStatic = 0, kDynamic = 1 };
// We rely on kStaticMutex being 0 as it is to what the linker initializes
@@ -1422,7 +1424,7 @@ class GTEST_API_ Mutex {
// platforms. That macro is used as a defensive measure to prevent against
// inadvertent misuses of MutexLock like "MutexLock(&mu)" rather than
// "MutexLock l(&mu)". Hence the typedef trick below.
-class GTestMutexLock {
+class [[nodiscard]] GTestMutexLock {
public:
explicit GTestMutexLock(Mutex& mutex) : mutex_(mutex) { mutex_.lock(); }
~GTestMutexLock() { mutex_.unlock(); }
@@ -1438,14 +1440,14 @@ typedef GTestMutexLock MutexLock;
// Base class for ValueHolder<T>. Allows a caller to hold and delete a value
// without knowing its type.
-class ThreadLocalValueHolderBase {
+class [[nodiscard]] ThreadLocalValueHolderBase {
public:
virtual ~ThreadLocalValueHolderBase() {}
};
// Provides a way for a thread to send notifications to a ThreadLocal
// regardless of its parameter type.
-class ThreadLocalBase {
+class [[nodiscard]] ThreadLocalBase {
public:
// Creates a new ValueHolder<T> object holding a default value passed to
// this ThreadLocal<T>'s constructor and returns it. It is the caller's
@@ -1465,7 +1467,7 @@ class ThreadLocalBase {
// Maps a thread to a set of ThreadLocals that have values instantiated on that
// thread and notifies them when the thread exits. A ThreadLocal instance is
// expected to persist until all threads it has values on have terminated.
-class GTEST_API_ ThreadLocalRegistry {
+class GTEST_API_ [[nodiscard]] ThreadLocalRegistry {
public:
// Registers thread_local_instance as having value on the current thread.
// Returns a value that can be used to identify the thread from other threads.
@@ -1477,7 +1479,7 @@ class GTEST_API_ ThreadLocalRegistry {
const ThreadLocalBase* thread_local_instance);
};
-class GTEST_API_ ThreadWithParamBase {
+class GTEST_API_ [[nodiscard]] ThreadWithParamBase {
public:
void Join();
@@ -1497,7 +1499,7 @@ class GTEST_API_ ThreadWithParamBase {
// Helper class for testing Google Test's multi-threading constructs.
template <typename T>
-class ThreadWithParam : public ThreadWithParamBase {
+class [[nodiscard]] ThreadWithParam : public ThreadWithParamBase {
public:
typedef void UserThreadFunc(T);
@@ -1552,7 +1554,7 @@ class ThreadWithParam : public ThreadWithParamBase {
// object managed by Google Test will be leaked as long as all threads
// using Google Test have exited when main() returns.
template <typename T>
-class ThreadLocal : public ThreadLocalBase {
+class [[nodiscard]] ThreadLocal : public ThreadLocalBase {
public:
ThreadLocal() : default_factory_(new DefaultValueHolderFactory()) {}
explicit ThreadLocal(const T& value)
@@ -1637,7 +1639,7 @@ class ThreadLocal : public ThreadLocalBase {
#elif GTEST_HAS_PTHREAD
// MutexBase and Mutex implement mutex on pthreads-based platforms.
-class MutexBase {
+class [[nodiscard]] MutexBase {
public:
// Acquires this mutex.
void lock() {
@@ -1695,7 +1697,7 @@ class MutexBase {
// The Mutex class can only be used for mutexes created at runtime. It
// shares its API with MutexBase otherwise.
-class Mutex : public MutexBase {
+class [[nodiscard]] Mutex : public MutexBase {
public:
Mutex() {
GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_init(&mutex_, nullptr));
@@ -1713,7 +1715,7 @@ class Mutex : public MutexBase {
// platforms. That macro is used as a defensive measure to prevent against
// inadvertent misuses of MutexLock like "MutexLock(&mu)" rather than
// "MutexLock l(&mu)". Hence the typedef trick below.
-class GTestMutexLock {
+class [[nodiscard]] GTestMutexLock {
public:
explicit GTestMutexLock(MutexBase& mutex) : mutex_(mutex) { mutex_.lock(); }
~GTestMutexLock() { mutex_.unlock(); }
@@ -1733,7 +1735,7 @@ typedef GTestMutexLock MutexLock;
// C-linkage. Therefore it cannot be templatized to access
// ThreadLocal<T>. Hence the need for class
// ThreadLocalValueHolderBase.
-class GTEST_API_ ThreadLocalValueHolderBase {
+class GTEST_API_ [[nodiscard]] ThreadLocalValueHolderBase {
public:
virtual ~ThreadLocalValueHolderBase() = default;
};
@@ -1746,7 +1748,7 @@ extern "C" inline void DeleteThreadLocalValue(void* value_holder) {
// Implements thread-local storage on pthreads-based systems.
template <typename T>
-class GTEST_API_ ThreadLocal {
+class GTEST_API_ [[nodiscard]] ThreadLocal {
public:
ThreadLocal()
: key_(CreateKey()), default_factory_(new DefaultValueHolderFactory()) {}
@@ -1859,7 +1861,7 @@ class GTEST_API_ ThreadLocal {
// mutex is not supported - using Google Test in multiple threads is not
// supported on such platforms.
-class Mutex {
+class [[nodiscard]] Mutex {
public:
Mutex() {}
void lock() {}
@@ -1877,7 +1879,7 @@ class Mutex {
// platforms. That macro is used as a defensive measure to prevent against
// inadvertent misuses of MutexLock like "MutexLock(&mu)" rather than
// "MutexLock l(&mu)". Hence the typedef trick below.
-class GTestMutexLock {
+class [[nodiscard]] GTestMutexLock {
public:
explicit GTestMutexLock(Mutex&) {} // NOLINT
};
@@ -1885,7 +1887,7 @@ class GTestMutexLock {
typedef GTestMutexLock MutexLock;
template <typename T>
-class GTEST_API_ ThreadLocal {
+class GTEST_API_ [[nodiscard]] ThreadLocal {
public:
ThreadLocal() : value_() {}
explicit ThreadLocal(const T& value) : value_(value) {}
@@ -2193,7 +2195,7 @@ constexpr BiggestInt kMaxBiggestInt = (std::numeric_limits<BiggestInt>::max)();
// needs. Other types can be easily added in the future if need
// arises.
template <size_t size>
-class TypeWithSize {
+class [[nodiscard]] TypeWithSize {
public:
// This prevents the user from using TypeWithSize<N> with incorrect
// values of N.
@@ -2202,7 +2204,7 @@ class TypeWithSize {
// The specialization for size 4.
template <>
-class TypeWithSize<4> {
+class [[nodiscard]] TypeWithSize<4> {
public:
using Int = std::int32_t;
using UInt = std::uint32_t;
@@ -2210,7 +2212,7 @@ class TypeWithSize<4> {
// The specialization for size 8.
template <>
-class TypeWithSize<8> {
+class [[nodiscard]] TypeWithSize<8> {
public:
using Int = std::int64_t;
using UInt = std::uint64_t;
diff --git a/googletest/include/gtest/internal/gtest-string.h b/googletest/include/gtest/internal/gtest-string.h
index 7c05b58..2363034 100644
--- a/googletest/include/gtest/internal/gtest-string.h
+++ b/googletest/include/gtest/internal/gtest-string.h
@@ -60,7 +60,7 @@ namespace testing {
namespace internal {
// String - an abstract class holding static string utilities.
-class GTEST_API_ String {
+class GTEST_API_ [[nodiscard]] String {
public:
// Static utility methods
@@ -166,7 +166,7 @@ class GTEST_API_ String {
private:
String(); // Not meant to be instantiated.
-}; // class String
+}; // class String
// Gets the content of the stringstream's buffer as an std::string. Each '\0'
// character in the buffer is replaced with "\\0".