diff options
author | Abseil Team <absl-team@google.com> | 2021-01-05 12:21:27 -0500 |
---|---|---|
committer | Derek Mauro <dmauro@google.com> | 2021-01-13 20:58:57 -0500 |
commit | f8304d762e0ed119d3d1c72deb1976dc80029db5 (patch) | |
tree | 0e79c6abd727e495fc3aa9aab6482b1ceb0b2f4d /googletest/include/gtest/gtest-printers.h | |
parent | 95a9bdd9f91222e34d7ef50757e24351d73927b9 (diff) | |
download | googletest-f8304d762e0ed119d3d1c72deb1976dc80029db5.tar.gz googletest-f8304d762e0ed119d3d1c72deb1976dc80029db5.zip |
Googletest export
Add support for printing incomplete types in the universal printer.
PiperOrigin-RevId: 350154637
Diffstat (limited to 'googletest/include/gtest/gtest-printers.h')
-rw-r--r-- | googletest/include/gtest/gtest-printers.h | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/googletest/include/gtest/gtest-printers.h b/googletest/include/gtest/gtest-printers.h index 463f0aff..d3292247 100644 --- a/googletest/include/gtest/gtest-printers.h +++ b/googletest/include/gtest/gtest-printers.h @@ -261,16 +261,23 @@ struct ConvertibleToStringViewPrinter { GTEST_API_ void PrintBytesInObjectTo(const unsigned char* obj_bytes, size_t count, ::std::ostream* os); -struct FallbackPrinter { - template <typename T> +struct RawBytesPrinter { + // SFINAE on `sizeof` to make sure we have a complete type. + template <typename T, size_t = sizeof(T)> static void PrintValue(const T& value, ::std::ostream* os) { PrintBytesInObjectTo( - static_cast<const unsigned char*>( - reinterpret_cast<const void*>(std::addressof(value))), + reinterpret_cast<const unsigned char*>(std::addressof(value)), sizeof(value), os); } }; +struct FallbackPrinter { + template <typename T> + static void PrintValue(const T&, ::std::ostream* os) { + *os << "(incomplete type)"; + } +}; + // Try every printer in order and return the first one that works. template <typename T, typename E, typename Printer, typename... Printers> struct FindFirstPrinter : FindFirstPrinter<T, E, Printers...> {}; @@ -297,7 +304,7 @@ void PrintWithFallback(const T& value, ::std::ostream* os) { T, void, ContainerPrinter, FunctionPointerPrinter, PointerPrinter, internal_stream_operator_without_lexical_name_lookup::StreamPrinter, ProtobufPrinter, ConvertibleToIntegerPrinter, - ConvertibleToStringViewPrinter, FallbackPrinter>::type; + ConvertibleToStringViewPrinter, RawBytesPrinter, FallbackPrinter>::type; Printer::PrintValue(value, os); } |