From 54e331b88bca8e9ab9de55153a3e6d295299aad0 Mon Sep 17 00:00:00 2001 From: James Dennett Date: Thu, 10 May 2018 22:39:19 -0700 Subject: Add support for versioned standard libraries. This canonicalizes demangled names by omitting a nested inline namespace within namespace std if the name of the nested namespace begins with a double underscore. This improves compatibility with libc++. --- .../include/gtest/internal/gtest-type-util.h.pump | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/googletest/include/gtest/internal/gtest-type-util.h.pump b/googletest/include/gtest/internal/gtest-type-util.h.pump index 251fdf0..6122862 100644 --- a/googletest/include/gtest/internal/gtest-type-util.h.pump +++ b/googletest/include/gtest/internal/gtest-type-util.h.pump @@ -54,6 +54,22 @@ $var n = 50 $$ Maximum length of type lists we want to support. namespace testing { namespace internal { + +// Canonicalizes a given name with respect to the Standard C++ Library. +// This handles removing the inline namespace within `std` that is +// used by various standard libraries (e.g., `std::__1`). Names outside +// of namespace std are returned unmodified. +inline std::string CanonicalizeForStdLibVersioning(std::string s) { + static constexpr char prefix[] = "std::__"; + if (s.compare(0, strlen(prefix), prefix) == 0) { + auto end = s.find("::", strlen(prefix)); + if (end != s.npos) { + // Erase the `::__` plus whatever was between that and the next `::`. + s.erase(strlen("std"), strlen("::__") + end - strlen(prefix)); + } + } + return s; +} // GetTypeName() returns a human-readable name of type T. // NB: This function is also used in Google Mock, so don't move it inside of @@ -71,9 +87,9 @@ std::string GetTypeName() { using abi::__cxa_demangle; # endif // GTEST_HAS_CXXABI_H_ char* const readable_name = __cxa_demangle(name, 0, 0, &status); - const std::string name_str(status == 0 ? readable_name : name); + std::string name_str(status == 0 ? readable_name : name); free(readable_name); - return name_str; + return CanonicalizeForStdLibVersioning(std::move(name_str)); # else return name; # endif // GTEST_HAS_CXXABI_H_ || __HP_aCC -- cgit v0.12