summaryrefslogtreecommitdiffstats
path: root/googletest/include/gtest
diff options
context:
space:
mode:
authorKrystian Kuzniarek <krystian.kuzniarek@gmail.com>2020-03-07 16:25:51 (GMT)
committerKrystian Kuzniarek <krystian.kuzniarek@gmail.com>2020-05-29 11:59:42 (GMT)
commiteb3953f805d0ed9054dba78b8e842caba0b539c2 (patch)
tree431b8b25a99617b39a0ba5c8e011e545a6e45865 /googletest/include/gtest
parent843267f0f1482b470fe14201edfda2c64b68232a (diff)
downloadgoogletest-eb3953f805d0ed9054dba78b8e842caba0b539c2.zip
googletest-eb3953f805d0ed9054dba78b8e842caba0b539c2.tar.gz
googletest-eb3953f805d0ed9054dba78b8e842caba0b539c2.tar.bz2
make UniversalPrinter<std::any> support RTTIrefs/pull/2742/head
Diffstat (limited to 'googletest/include/gtest')
-rw-r--r--googletest/include/gtest/gtest-printers.h11
-rw-r--r--googletest/include/gtest/internal/gtest-type-util.h38
2 files changed, 30 insertions, 19 deletions
diff --git a/googletest/include/gtest/gtest-printers.h b/googletest/include/gtest/gtest-printers.h
index 67c87f4..718e6f1 100644
--- a/googletest/include/gtest/gtest-printers.h
+++ b/googletest/include/gtest/gtest-printers.h
@@ -688,13 +688,20 @@ class UniversalPrinter<Any> {
public:
static void Print(const Any& value, ::std::ostream* os) {
if (value.has_value())
- *os << "'any' type with value of type " << GetTypeName();
+ *os << "'any' type with value of type " << GetTypeName(value);
else
*os << "'any' type with no value";
}
private:
- static std::string GetTypeName() { return "the element type"; }
+ static std::string GetTypeName(const Any& value) {
+#if GTEST_HAS_RTTI
+ return internal::GetTypeName(value.type());
+#else
+ static_cast<void>(value); // possibly unused
+ return "the element type";
+#endif // GTEST_HAS_RTTI
+ }
};
#endif // GTEST_INTERNAL_HAS_ANY
diff --git a/googletest/include/gtest/internal/gtest-type-util.h b/googletest/include/gtest/internal/gtest-type-util.h
index 082fdad..c3326f2 100644
--- a/googletest/include/gtest/internal/gtest-type-util.h
+++ b/googletest/include/gtest/internal/gtest-type-util.h
@@ -64,34 +64,38 @@ inline std::string CanonicalizeForStdLibVersioning(std::string s) {
return s;
}
-// GetTypeName<T>() returns a human-readable name of type T.
-// NB: This function is also used in Google Mock, so don't move it inside of
-// the typed-test-only section below.
-template <typename T>
-std::string GetTypeName() {
-# if GTEST_HAS_RTTI
-
- const char* const name = typeid(T).name();
-# if GTEST_HAS_CXXABI_H_ || defined(__HP_aCC)
+#if GTEST_HAS_RTTI
+// GetTypeName(const std::type_info&) returns a human-readable name of type T.
+inline std::string GetTypeName(const std::type_info& type) {
+ const char* const name = type.name();
+#if GTEST_HAS_CXXABI_H_ || defined(__HP_aCC)
int status = 0;
// gcc's implementation of typeid(T).name() mangles the type name,
// so we have to demangle it.
-# if GTEST_HAS_CXXABI_H_
+#if GTEST_HAS_CXXABI_H_
using abi::__cxa_demangle;
-# endif // GTEST_HAS_CXXABI_H_
+#endif // GTEST_HAS_CXXABI_H_
char* const readable_name = __cxa_demangle(name, nullptr, nullptr, &status);
const std::string name_str(status == 0 ? readable_name : name);
free(readable_name);
return CanonicalizeForStdLibVersioning(name_str);
-# else
+#else
return name;
-# endif // GTEST_HAS_CXXABI_H_ || __HP_aCC
-
-# else
+#endif // GTEST_HAS_CXXABI_H_ || __HP_aCC
+}
+#endif // GTEST_HAS_RTTI
+// GetTypeName<T>() returns a human-readable name of type T if and only if
+// RTTI is enabled, otherwise it returns a dummy type name.
+// NB: This function is also used in Google Mock, so don't move it inside of
+// the typed-test-only section below.
+template <typename T>
+std::string GetTypeName() {
+#if GTEST_HAS_RTTI
+ return GetTypeName(typeid(T));
+#else
return "<type>";
-
-# endif // GTEST_HAS_RTTI
+#endif // GTEST_HAS_RTTI
}
#if GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P