summaryrefslogtreecommitdiffstats
path: root/googletest/include/gtest
diff options
context:
space:
mode:
authorCopybara-Service <copybara-worker@google.com>2023-05-02 14:52:02 (GMT)
committerCopybara-Service <copybara-worker@google.com>2023-05-02 14:52:02 (GMT)
commita3580180d16923d6d5f488e20b3814608a892f17 (patch)
treeebfcea4239151da81e75af15f539242ea26b62b1 /googletest/include/gtest
parentf345b2ca6adb1b505049190867eedf24d3b5eaa3 (diff)
parent76bce79a3493aa157b3baca833fec1e3934d3512 (diff)
downloadgoogletest-a3580180d16923d6d5f488e20b3814608a892f17.zip
googletest-a3580180d16923d6d5f488e20b3814608a892f17.tar.gz
googletest-a3580180d16923d6d5f488e20b3814608a892f17.tar.bz2
Merge pull request #4146 from lygstate:fixes_std_pair_diff
PiperOrigin-RevId: 528781910 Change-Id: I4038332a6255921792bfb4a8098aa84243d48e15
Diffstat (limited to 'googletest/include/gtest')
-rw-r--r--googletest/include/gtest/internal/gtest-type-util.h30
1 files changed, 30 insertions, 0 deletions
diff --git a/googletest/include/gtest/internal/gtest-type-util.h b/googletest/include/gtest/internal/gtest-type-util.h
index 17a470b..f94cf61 100644
--- a/googletest/include/gtest/internal/gtest-type-util.h
+++ b/googletest/include/gtest/internal/gtest-type-util.h
@@ -67,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;
}
@@ -85,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