diff --git a/deps/googletest/include/gtest/gtest-printers.h b/deps/googletest/include/gtest/gtest-printers.h index 198a7693493a33..048c32db2e7c2e 100644 --- a/deps/googletest/include/gtest/gtest-printers.h +++ b/deps/googletest/include/gtest/gtest-printers.h @@ -104,15 +104,19 @@ #ifndef GOOGLETEST_INCLUDE_GTEST_GTEST_PRINTERS_H_ #define GOOGLETEST_INCLUDE_GTEST_GTEST_PRINTERS_H_ +#include #include #include +#include #include // NOLINT #include #include +#include #include #include #include #include +#include #include #ifdef GTEST_HAS_ABSL @@ -245,8 +249,8 @@ struct StreamPrinter { // ADL (possibly involving implicit conversions). // (Use SFINAE via return type, because it seems GCC < 12 doesn't handle name // lookup properly when we do it in the template parameter list.) - static auto PrintValue(const T& value, - ::std::ostream* os) -> decltype((void)(*os << value)) { + static auto PrintValue(const T& value, ::std::ostream* os) + -> decltype((void)(*os << value)) { // Call streaming operator found by ADL, possibly with implicit conversions // of the arguments. *os << value; @@ -521,11 +525,15 @@ GTEST_API_ void PrintTo(wchar_t wc, ::std::ostream* os); GTEST_API_ void PrintTo(char32_t c, ::std::ostream* os); inline void PrintTo(char16_t c, ::std::ostream* os) { - PrintTo(ImplicitCast_(c), os); + // TODO(b/418738869): Incorrect for values not representing valid codepoints. + // Also see https://github.com/google/googletest/issues/4762. + PrintTo(static_cast(c), os); } #ifdef __cpp_lib_char8_t inline void PrintTo(char8_t c, ::std::ostream* os) { - PrintTo(ImplicitCast_(c), os); + // TODO(b/418738869): Incorrect for values not representing valid codepoints. + // Also see https://github.com/google/googletest/issues/4762. + PrintTo(static_cast(c), os); } #endif @@ -695,44 +703,63 @@ void PrintRawArrayTo(const T a[], size_t count, ::std::ostream* os) { } } -// Overloads for ::std::string. -GTEST_API_ void PrintStringTo(const ::std::string& s, ::std::ostream* os); +// Overloads for ::std::string and ::std::string_view +GTEST_API_ void PrintStringTo(::std::string_view s, ::std::ostream* os); inline void PrintTo(const ::std::string& s, ::std::ostream* os) { PrintStringTo(s, os); } +inline void PrintTo(::std::string_view s, ::std::ostream* os) { + PrintStringTo(s, os); +} -// Overloads for ::std::u8string +// Overloads for ::std::u8string and ::std::u8string_view #ifdef __cpp_lib_char8_t -GTEST_API_ void PrintU8StringTo(const ::std::u8string& s, ::std::ostream* os); +GTEST_API_ void PrintU8StringTo(::std::u8string_view s, ::std::ostream* os); inline void PrintTo(const ::std::u8string& s, ::std::ostream* os) { PrintU8StringTo(s, os); } +inline void PrintTo(::std::u8string_view s, ::std::ostream* os) { + PrintU8StringTo(s, os); +} #endif -// Overloads for ::std::u16string -GTEST_API_ void PrintU16StringTo(const ::std::u16string& s, ::std::ostream* os); +// Overloads for ::std::u16string and ::std::u16string_view +GTEST_API_ void PrintU16StringTo(::std::u16string_view s, ::std::ostream* os); inline void PrintTo(const ::std::u16string& s, ::std::ostream* os) { PrintU16StringTo(s, os); } +inline void PrintTo(::std::u16string_view s, ::std::ostream* os) { + PrintU16StringTo(s, os); +} -// Overloads for ::std::u32string -GTEST_API_ void PrintU32StringTo(const ::std::u32string& s, ::std::ostream* os); +// Overloads for ::std::u32string and ::std::u32string_view +GTEST_API_ void PrintU32StringTo(::std::u32string_view s, ::std::ostream* os); inline void PrintTo(const ::std::u32string& s, ::std::ostream* os) { PrintU32StringTo(s, os); } +inline void PrintTo(::std::u32string_view s, ::std::ostream* os) { + PrintU32StringTo(s, os); +} -// Overloads for ::std::wstring. +// Overloads for ::std::wstring and ::std::wstring_view #if GTEST_HAS_STD_WSTRING -GTEST_API_ void PrintWideStringTo(const ::std::wstring& s, ::std::ostream* os); +GTEST_API_ void PrintWideStringTo(::std::wstring_view s, ::std::ostream* os); inline void PrintTo(const ::std::wstring& s, ::std::ostream* os) { PrintWideStringTo(s, os); } +inline void PrintTo(::std::wstring_view s, ::std::ostream* os) { + PrintWideStringTo(s, os); +} #endif // GTEST_HAS_STD_WSTRING #if GTEST_INTERNAL_HAS_STRING_VIEW -// Overload for internal::StringView. +// Overload for internal::StringView. Needed for build configurations where +// internal::StringView is an alias for absl::string_view, but absl::string_view +// is a distinct type from std::string_view. +template , int> = 0> inline void PrintTo(internal::StringView sp, ::std::ostream* os) { - PrintTo(::std::string(sp), os); + PrintStringTo(sp, os); } #endif // GTEST_INTERNAL_HAS_STRING_VIEW @@ -890,14 +917,11 @@ class UniversalPrinter { template class UniversalPrinter : public UniversalPrinter {}; -#if GTEST_INTERNAL_HAS_ANY - -// Printer for std::any / absl::any - +// Printer for std::any template <> -class UniversalPrinter { +class UniversalPrinter { public: - static void Print(const Any& value, ::std::ostream* os) { + static void Print(const std::any& value, ::std::ostream* os) { if (value.has_value()) { *os << "value of type " << GetTypeName(value); } else { @@ -906,7 +930,7 @@ class UniversalPrinter { } private: - static std::string GetTypeName(const Any& value) { + static std::string GetTypeName(const std::any& value) { #if GTEST_HAS_RTTI return internal::GetTypeName(value.type()); #else @@ -916,16 +940,11 @@ class UniversalPrinter { } }; -#endif // GTEST_INTERNAL_HAS_ANY - -#if GTEST_INTERNAL_HAS_OPTIONAL - -// Printer for std::optional / absl::optional - +// Printer for std::optional template -class UniversalPrinter> { +class UniversalPrinter> { public: - static void Print(const Optional& value, ::std::ostream* os) { + static void Print(const std::optional& value, ::std::ostream* os) { *os << '('; if (!value) { *os << "nullopt"; @@ -937,29 +956,18 @@ class UniversalPrinter> { }; template <> -class UniversalPrinter { +class UniversalPrinter { public: - static void Print(decltype(Nullopt()), ::std::ostream* os) { - *os << "(nullopt)"; - } + static void Print(std::nullopt_t, ::std::ostream* os) { *os << "(nullopt)"; } }; -#endif // GTEST_INTERNAL_HAS_OPTIONAL - -#if GTEST_INTERNAL_HAS_VARIANT - -// Printer for std::variant / absl::variant - +// Printer for std::variant template -class UniversalPrinter> { +class UniversalPrinter> { public: - static void Print(const Variant& value, ::std::ostream* os) { + static void Print(const std::variant& value, ::std::ostream* os) { *os << '('; -#ifdef GTEST_HAS_ABSL - absl::visit(Visitor{os, value.index()}, value); -#else std::visit(Visitor{os, value.index()}, value); -#endif // GTEST_HAS_ABSL *os << ')'; } @@ -976,8 +984,6 @@ class UniversalPrinter> { }; }; -#endif // GTEST_INTERNAL_HAS_VARIANT - // UniversalPrintArray(begin, len, os) prints an array of 'len' // elements, starting at address 'begin'. template diff --git a/deps/googletest/include/gtest/gtest.h b/deps/googletest/include/gtest/gtest.h index 7be0caaf515cf8..cbe680c1adb266 100644 --- a/deps/googletest/include/gtest/gtest.h +++ b/deps/googletest/include/gtest/gtest.h @@ -1693,7 +1693,7 @@ class WithParamInterface { // The current parameter value. Is also available in the test fixture's // constructor. - static const ParamType& GetParam() { + [[nodiscard]] static const ParamType& GetParam() { GTEST_CHECK_(parameter_ != nullptr) << "GetParam() can only be called inside a value-parameterized test " << "-- did you intend to write TEST_P instead of TEST_F?"; diff --git a/deps/googletest/include/gtest/internal/gtest-internal.h b/deps/googletest/include/gtest/internal/gtest-internal.h index dcab397e92320a..808d89be91439a 100644 --- a/deps/googletest/include/gtest/internal/gtest-internal.h +++ b/deps/googletest/include/gtest/internal/gtest-internal.h @@ -290,17 +290,17 @@ class FloatingPoint { // around may change its bits, although the new value is guaranteed // to be also a NAN. Therefore, don't expect this constructor to // preserve the bits in x when x is a NAN. - explicit FloatingPoint(const RawType& x) { u_.value_ = x; } + explicit FloatingPoint(RawType x) { memcpy(&bits_, &x, sizeof(x)); } // Static methods // Reinterprets a bit pattern as a floating-point number. // // This function is needed to test the AlmostEquals() method. - static RawType ReinterpretBits(const Bits bits) { - FloatingPoint fp(0); - fp.u_.bits_ = bits; - return fp.u_.value_; + static RawType ReinterpretBits(Bits bits) { + RawType fp; + memcpy(&fp, &bits, sizeof(fp)); + return fp; } // Returns the floating-point number that represent positive infinity. @@ -309,16 +309,16 @@ class FloatingPoint { // Non-static methods // Returns the bits that represents this number. - const Bits& bits() const { return u_.bits_; } + const Bits& bits() const { return bits_; } // Returns the exponent bits of this number. - Bits exponent_bits() const { return kExponentBitMask & u_.bits_; } + Bits exponent_bits() const { return kExponentBitMask & bits_; } // Returns the fraction bits of this number. - Bits fraction_bits() const { return kFractionBitMask & u_.bits_; } + Bits fraction_bits() const { return kFractionBitMask & bits_; } // Returns the sign bit of this number. - Bits sign_bit() const { return kSignBitMask & u_.bits_; } + Bits sign_bit() const { return kSignBitMask & bits_; } // Returns true if and only if this is NAN (not a number). bool is_nan() const { @@ -332,23 +332,16 @@ class FloatingPoint { // // - returns false if either number is (or both are) NAN. // - treats really large numbers as almost equal to infinity. - // - thinks +0.0 and -0.0 are 0 DLP's apart. + // - thinks +0.0 and -0.0 are 0 ULP's apart. bool AlmostEquals(const FloatingPoint& rhs) const { // The IEEE standard says that any comparison operation involving // a NAN must return false. if (is_nan() || rhs.is_nan()) return false; - return DistanceBetweenSignAndMagnitudeNumbers(u_.bits_, rhs.u_.bits_) <= - kMaxUlps; + return DistanceBetweenSignAndMagnitudeNumbers(bits_, rhs.bits_) <= kMaxUlps; } private: - // The data type used to store the actual floating-point number. - union FloatingPointUnion { - RawType value_; // The raw floating-point number. - Bits bits_; // The bits that represent the number. - }; - // Converts an integer from the sign-and-magnitude representation to // the biased representation. More precisely, let N be 2 to the // power of (kBitCount - 1), an integer x is represented by the @@ -364,7 +357,7 @@ class FloatingPoint { // // Read https://en.wikipedia.org/wiki/Signed_number_representations // for more details on signed number representations. - static Bits SignAndMagnitudeToBiased(const Bits& sam) { + static Bits SignAndMagnitudeToBiased(Bits sam) { if (kSignBitMask & sam) { // sam represents a negative number. return ~sam + 1; @@ -376,14 +369,13 @@ class FloatingPoint { // Given two numbers in the sign-and-magnitude representation, // returns the distance between them as an unsigned number. - static Bits DistanceBetweenSignAndMagnitudeNumbers(const Bits& sam1, - const Bits& sam2) { + static Bits DistanceBetweenSignAndMagnitudeNumbers(Bits sam1, Bits sam2) { const Bits biased1 = SignAndMagnitudeToBiased(sam1); const Bits biased2 = SignAndMagnitudeToBiased(sam2); return (biased1 >= biased2) ? (biased1 - biased2) : (biased2 - biased1); } - FloatingPointUnion u_; + Bits bits_; // The bits that represent the number. }; // Typedefs the instances of the FloatingPoint template class that we diff --git a/deps/googletest/include/gtest/internal/gtest-port.h b/deps/googletest/include/gtest/internal/gtest-port.h index 4cfc16c03e9d38..06a5a8e6f31935 100644 --- a/deps/googletest/include/gtest/internal/gtest-port.h +++ b/deps/googletest/include/gtest/internal/gtest-port.h @@ -198,21 +198,8 @@ // suppressed (constant conditional). // GTEST_INTENTIONAL_CONST_COND_POP_ - finish code section where MSVC C4127 // is suppressed. -// GTEST_INTERNAL_HAS_ANY - for enabling UniversalPrinter or -// UniversalPrinter specializations. -// Always defined to 0 or 1. -// GTEST_INTERNAL_HAS_OPTIONAL - for enabling UniversalPrinter -// or -// UniversalPrinter -// specializations. Always defined to 0 or 1. // GTEST_INTERNAL_HAS_STD_SPAN - for enabling UniversalPrinter // specializations. Always defined to 0 or 1 -// GTEST_INTERNAL_HAS_STRING_VIEW - for enabling Matcher or -// Matcher -// specializations. Always defined to 0 or 1. -// GTEST_INTERNAL_HAS_VARIANT - for enabling UniversalPrinter or -// UniversalPrinter -// specializations. Always defined to 0 or 1. // GTEST_USE_OWN_FLAGFILE_FLAG_ - Always defined to 0 or 1. // GTEST_HAS_CXXABI_H_ - Always defined to 0 or 1. // GTEST_CAN_STREAM_RESULTS_ - Always defined to 0 or 1. @@ -282,10 +269,14 @@ // Detect C++ feature test macros as gracefully as possible. // MSVC >= 19.15, Clang >= 3.4.1, and GCC >= 4.1.2 support feature test macros. -#if GTEST_INTERNAL_CPLUSPLUS_LANG >= 202002L && \ - (!defined(__has_include) || GTEST_INTERNAL_HAS_INCLUDE()) -#include // C++20 and later -#elif (!defined(__has_include) || GTEST_INTERNAL_HAS_INCLUDE()) +// +// GCC15 warns that is deprecated in C++17 and suggests using +// instead, even though is not available in C++17 mode prior +// to GCC9. +#if GTEST_INTERNAL_CPLUSPLUS_LANG >= 202002L || \ + GTEST_INTERNAL_HAS_INCLUDE() +#include // C++20 or support. +#else #include // Pre-C++20 #endif @@ -2331,73 +2322,6 @@ const char* StringFromGTestEnv(const char* flag, const char* default_val); } // namespace internal } // namespace testing -#ifdef GTEST_HAS_ABSL -// Always use absl::any for UniversalPrinter<> specializations if googletest -// is built with absl support. -#define GTEST_INTERNAL_HAS_ANY 1 -#include "absl/types/any.h" -namespace testing { -namespace internal { -using Any = ::absl::any; -} // namespace internal -} // namespace testing -#else -#if defined(__cpp_lib_any) || (GTEST_INTERNAL_HAS_INCLUDE() && \ - GTEST_INTERNAL_CPLUSPLUS_LANG >= 201703L && \ - (!defined(_MSC_VER) || GTEST_HAS_RTTI)) -// Otherwise for C++17 and higher use std::any for UniversalPrinter<> -// specializations. -#define GTEST_INTERNAL_HAS_ANY 1 -#include -namespace testing { -namespace internal { -using Any = ::std::any; -} // namespace internal -} // namespace testing -// The case where absl is configured NOT to alias std::any is not -// supported. -#endif // __cpp_lib_any -#endif // GTEST_HAS_ABSL - -#ifndef GTEST_INTERNAL_HAS_ANY -#define GTEST_INTERNAL_HAS_ANY 0 -#endif - -#ifdef GTEST_HAS_ABSL -// Always use absl::optional for UniversalPrinter<> specializations if -// googletest is built with absl support. -#define GTEST_INTERNAL_HAS_OPTIONAL 1 -#include "absl/types/optional.h" -namespace testing { -namespace internal { -template -using Optional = ::absl::optional; -inline ::absl::nullopt_t Nullopt() { return ::absl::nullopt; } -} // namespace internal -} // namespace testing -#else -#if defined(__cpp_lib_optional) || (GTEST_INTERNAL_HAS_INCLUDE() && \ - GTEST_INTERNAL_CPLUSPLUS_LANG >= 201703L) -// Otherwise for C++17 and higher use std::optional for UniversalPrinter<> -// specializations. -#define GTEST_INTERNAL_HAS_OPTIONAL 1 -#include -namespace testing { -namespace internal { -template -using Optional = ::std::optional; -inline ::std::nullopt_t Nullopt() { return ::std::nullopt; } -} // namespace internal -} // namespace testing -// The case where absl is configured NOT to alias std::optional is not -// supported. -#endif // __cpp_lib_optional -#endif // GTEST_HAS_ABSL - -#ifndef GTEST_INTERNAL_HAS_OPTIONAL -#define GTEST_INTERNAL_HAS_OPTIONAL 0 -#endif - #if defined(__cpp_lib_span) || (GTEST_INTERNAL_HAS_INCLUDE() && \ GTEST_INTERNAL_CPLUSPLUS_LANG >= 202002L) #define GTEST_INTERNAL_HAS_STD_SPAN 1 @@ -2439,38 +2363,6 @@ using StringView = ::std::string_view; #define GTEST_INTERNAL_HAS_STRING_VIEW 0 #endif -#ifdef GTEST_HAS_ABSL -// Always use absl::variant for UniversalPrinter<> specializations if googletest -// is built with absl support. -#define GTEST_INTERNAL_HAS_VARIANT 1 -#include "absl/types/variant.h" -namespace testing { -namespace internal { -template -using Variant = ::absl::variant; -} // namespace internal -} // namespace testing -#else -#if defined(__cpp_lib_variant) || (GTEST_INTERNAL_HAS_INCLUDE() && \ - GTEST_INTERNAL_CPLUSPLUS_LANG >= 201703L) -// Otherwise for C++17 and higher use std::variant for UniversalPrinter<> -// specializations. -#define GTEST_INTERNAL_HAS_VARIANT 1 -#include -namespace testing { -namespace internal { -template -using Variant = ::std::variant; -} // namespace internal -} // namespace testing -// The case where absl is configured NOT to alias std::variant is not supported. -#endif // __cpp_lib_variant -#endif // GTEST_HAS_ABSL - -#ifndef GTEST_INTERNAL_HAS_VARIANT -#define GTEST_INTERNAL_HAS_VARIANT 0 -#endif - #if (defined(__cpp_lib_three_way_comparison) || \ (GTEST_INTERNAL_HAS_INCLUDE() && \ GTEST_INTERNAL_CPLUSPLUS_LANG >= 201907L)) diff --git a/deps/googletest/src/gtest-printers.cc b/deps/googletest/src/gtest-printers.cc index e3acecba8e4dec..b5d8df6d879e6e 100644 --- a/deps/googletest/src/gtest-printers.cc +++ b/deps/googletest/src/gtest-printers.cc @@ -50,7 +50,7 @@ #include #include #include // NOLINT -#include +#include #include #include "gtest/internal/gtest-port.h" @@ -333,14 +333,14 @@ void PrintTo(__int128_t v, ::std::ostream* os) { // Prints the given array of characters to the ostream. CharType must be either // char, char8_t, char16_t, char32_t, or wchar_t. -// The array starts at begin, the length is len, it may include '\0' characters -// and may not be NUL-terminated. +// The array starts at begin (which may be nullptr) and contains len characters. +// The array may include '\0' characters and may not be NUL-terminated. template GTEST_ATTRIBUTE_NO_SANITIZE_MEMORY_ GTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS_ GTEST_ATTRIBUTE_NO_SANITIZE_HWADDRESS_ GTEST_ATTRIBUTE_NO_SANITIZE_THREAD_ static CharFormat PrintCharsAsStringTo(const CharType* begin, size_t len, ostream* os) { - const char* const quote_prefix = GetCharWidthPrefix(*begin); + const char* const quote_prefix = GetCharWidthPrefix(CharType()); *os << quote_prefix << "\""; bool is_previous_hex = false; CharFormat print_format = kAsIs; @@ -522,7 +522,7 @@ void ConditionalPrintAsText(const char* str, size_t length, ostream* os) { } // anonymous namespace -void PrintStringTo(const ::std::string& s, ostream* os) { +void PrintStringTo(::std::string_view s, ostream* os) { if (PrintCharsAsStringTo(s.data(), s.size(), os) == kHexEscape) { if (GTEST_FLAG_GET(print_utf8)) { ConditionalPrintAsText(s.data(), s.size(), os); @@ -531,21 +531,21 @@ void PrintStringTo(const ::std::string& s, ostream* os) { } #ifdef __cpp_lib_char8_t -void PrintU8StringTo(const ::std::u8string& s, ostream* os) { +void PrintU8StringTo(::std::u8string_view s, ostream* os) { PrintCharsAsStringTo(s.data(), s.size(), os); } #endif -void PrintU16StringTo(const ::std::u16string& s, ostream* os) { +void PrintU16StringTo(::std::u16string_view s, ostream* os) { PrintCharsAsStringTo(s.data(), s.size(), os); } -void PrintU32StringTo(const ::std::u32string& s, ostream* os) { +void PrintU32StringTo(::std::u32string_view s, ostream* os) { PrintCharsAsStringTo(s.data(), s.size(), os); } #if GTEST_HAS_STD_WSTRING -void PrintWideStringTo(const ::std::wstring& s, ostream* os) { +void PrintWideStringTo(::std::wstring_view s, ostream* os) { PrintCharsAsStringTo(s.data(), s.size(), os); } #endif // GTEST_HAS_STD_WSTRING