diff --git a/googletest/include/gtest/gtest-printers.h b/googletest/include/gtest/gtest-printers.h index 8e4d2953..89215e62 100644 --- a/googletest/include/gtest/gtest-printers.h +++ b/googletest/include/gtest/gtest-printers.h @@ -891,6 +891,13 @@ class UniversalTersePrinter { UniversalPrint(value, os); } }; +template +class UniversalTersePrinter> { + public: + static void Print(std::reference_wrapper value, ::std::ostream* os) { + UniversalTersePrinter::Print(value.get(), os); + } +}; template class UniversalTersePrinter { public: diff --git a/googletest/test/googletest-printers-test.cc b/googletest/test/googletest-printers-test.cc index acfecf97..d2d88a52 100644 --- a/googletest/test/googletest-printers-test.cc +++ b/googletest/test/googletest-printers-test.cc @@ -37,6 +37,7 @@ #include #include #include +#include #include #include #include @@ -193,6 +194,11 @@ OutputStream& operator<<(OutputStream& os, return os; } +struct StreamableInLocal {}; +void operator<<(::std::ostream& os, const StreamableInLocal& /* x */) { + os << "StreamableInLocal"; +} + // A user-defined streamable but recursively-defined container type in // a user namespace, it mimics therefore std::filesystem::path or // boost::filesystem::path. @@ -1604,6 +1610,23 @@ TEST(PrintToStringTest, ContainsNonLatin) { "\n As Text: \"From ä — ẑ\""); } +TEST(PrintToStringTest, PrintStreamableInLocal) { + EXPECT_STREQ("StreamableInLocal", + PrintToString(foo::StreamableInLocal()).c_str()); +} + +TEST(PrintToStringTest, PrintReferenceToStreamableInLocal) { + foo::StreamableInLocal s; + std::reference_wrapper r(s); + EXPECT_STREQ("StreamableInLocal", PrintToString(r).c_str()); +} + +TEST(PrintToStringTest, PrintReferenceToStreamableInGlobal) { + StreamableInGlobal s; + std::reference_wrapper r(s); + EXPECT_STREQ("StreamableInGlobal", PrintToString(r).c_str()); +} + TEST(IsValidUTF8Test, IllFormedUTF8) { // The following test strings are ill-formed UTF-8 and are printed // as hex only (or ASCII, in case of ASCII bytes) because IsValidUTF8() is