aboutsummaryrefslogtreecommitdiff
path: root/googletest/include/gtest/internal/gtest-type-util.h
diff options
context:
space:
mode:
Diffstat (limited to 'googletest/include/gtest/internal/gtest-type-util.h')
-rw-r--r--googletest/include/gtest/internal/gtest-type-util.h55
1 files changed, 46 insertions, 9 deletions
diff --git a/googletest/include/gtest/internal/gtest-type-util.h b/googletest/include/gtest/internal/gtest-type-util.h
index b87a2e2c..f94cf614 100644
--- a/googletest/include/gtest/internal/gtest-type-util.h
+++ b/googletest/include/gtest/internal/gtest-type-util.h
@@ -30,20 +30,26 @@
// Type utilities needed for implementing typed and type-parameterized
// tests.
-// GOOGLETEST_CM0001 DO NOT DELETE
+// IWYU pragma: private, include "gtest/gtest.h"
+// IWYU pragma: friend gtest/.*
+// IWYU pragma: friend gmock/.*
#ifndef GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_TYPE_UTIL_H_
#define GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_TYPE_UTIL_H_
+#include <string>
+#include <type_traits>
+#include <typeinfo>
+
#include "gtest/internal/gtest-port.h"
// #ifdef __GNUC__ is too general here. It is possible to use gcc without using
// libstdc++ (which is where cxxabi.h comes from).
-# if GTEST_HAS_CXXABI_H_
-# include <cxxabi.h>
-# elif defined(__HP_aCC)
-# include <acxx_demangle.h>
-# endif // GTEST_HASH_CXXABI_H_
+#if GTEST_HAS_CXXABI_H_
+#include <cxxabi.h>
+#elif defined(__HP_aCC)
+#include <acxx_demangle.h>
+#endif // GTEST_HASH_CXXABI_H_
namespace testing {
namespace internal {
@@ -61,6 +67,22 @@ inline std::string CanonicalizeForStdLibVersioning(std::string s) {
s.erase(strlen("std"), end - strlen("std"));
}
}
+
+ // Strip redundant spaces in typename to match MSVC
+ // For example, std::pair<int, bool> -> std::pair<int,bool>
+ static const char to_search[] = ", ";
+ static const char replace_str[] = ",";
+ size_t pos = 0;
+ while (true) {
+ // Get the next occurrence from the current position
+ pos = s.find(to_search, pos);
+ if (pos == std::string::npos) {
+ break;
+ }
+ // Replace this occurrence of substring
+ s.replace(pos, strlen(to_search), replace_str);
+ pos += strlen(replace_str);
+ }
return s;
}
@@ -79,6 +101,20 @@ inline std::string GetTypeName(const std::type_info& type) {
const std::string name_str(status == 0 ? readable_name : name);
free(readable_name);
return CanonicalizeForStdLibVersioning(name_str);
+#elif defined(_MSC_VER)
+ // Strip struct and class due to differences between
+ // MSVC and other compilers. std::pair<int,bool> is printed as
+ // "struct std::pair<int,bool>" when using MSVC vs "std::pair<int, bool>" with
+ // other compilers.
+ std::string s = name;
+ // Only strip the leading "struct " and "class ", so uses rfind == 0 to
+ // ensure that
+ if (s.rfind("struct ", 0) == 0) {
+ s = s.substr(strlen("struct "));
+ } else if (s.rfind("class ", 0) == 0) {
+ s = s.substr(strlen("class "));
+ }
+ return s;
#else
return name;
#endif // GTEST_HAS_CXXABI_H_ || __HP_aCC
@@ -101,7 +137,9 @@ std::string GetTypeName() {
// A unique type indicating an empty node
struct None {};
-# define GTEST_TEMPLATE_ template <typename T> class
+#define GTEST_TEMPLATE_ \
+ template <typename T> \
+ class
// The template "selector" struct TemplateSel<Tmpl> is used to
// represent Tmpl, which must be a class template with one type
@@ -119,8 +157,7 @@ struct TemplateSel {
};
};
-# define GTEST_BIND_(TmplSel, T) \
- TmplSel::template Bind<T>::type
+#define GTEST_BIND_(TmplSel, T) TmplSel::template Bind<T>::type
template <GTEST_TEMPLATE_ Head_, GTEST_TEMPLATE_... Tail_>
struct Templates {