mirror of
https://github.com/google/googletest.git
synced 2026-10-28 18:07:18 +08:00
Don't reference std::char_traits<wchar_t> when !GTEST_HAS_STD_WSTRING
If the standard library doesn't support wide character strings, `std::char_traits<Char>` won't be defined, so the definition of `PrintTo` shouldn't reference it. Use `wstrlen` directly instead. PiperOrigin-RevId: 964168903 Change-Id: Ic628e6583679073b47bb1218dcf52b4c9eadaaf6
This commit is contained in:
parent
002d14757f
commit
aa1eefe02c
@ -1173,15 +1173,12 @@ class [[nodiscard]] UniversalTersePrinter<const wchar_t*> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
#endif
|
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
class [[nodiscard]] UniversalTersePrinter<wchar_t*> {
|
class [[nodiscard]] UniversalTersePrinter<wchar_t*>
|
||||||
public:
|
: public UniversalTersePrinter<const wchar_t*> {};
|
||||||
static void Print(wchar_t* str, ::std::ostream* os) {
|
|
||||||
UniversalTersePrinter<const wchar_t*>::Print(str, os);
|
#endif // GTEST_HAS_STD_WSTRING
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void UniversalTersePrint(const T& value, ::std::ostream* os) {
|
void UniversalTersePrint(const T& value, ::std::ostream* os) {
|
||||||
|
|||||||
@ -50,6 +50,7 @@
|
|||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <ios>
|
#include <ios>
|
||||||
#include <ostream> // NOLINT
|
#include <ostream> // NOLINT
|
||||||
|
#include <string>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
@ -422,6 +423,28 @@ void UniversalPrintArray(const wchar_t* begin, size_t len, ostream* os) {
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
template <typename Char>
|
||||||
|
size_t GetLength(const Char* s) {
|
||||||
|
return std::char_traits<Char>::length(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
#if !GTEST_HAS_STD_WSTRING
|
||||||
|
|
||||||
|
// If GTEST_HAS_STD_WSTRING is unset because the standard library has disabled
|
||||||
|
// wide character support, std::char_traits<wchar_t> won't be defined, which
|
||||||
|
// will cause a compile error, even if user code never actually could print a
|
||||||
|
// wide cstring. In that case, instead use `wcslen` directly.
|
||||||
|
//
|
||||||
|
// If `libc` _also_ lacks wide character support, this (and a bunch of other
|
||||||
|
// calls to wc functions) will fail to link, but only if user code actually
|
||||||
|
// uses them.
|
||||||
|
template <>
|
||||||
|
size_t GetLength<wchar_t>(const wchar_t* s) {
|
||||||
|
return wcslen(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // GTEST_HAS_STD_WSTRING
|
||||||
|
|
||||||
// Prints a null-terminated C-style string to the ostream.
|
// Prints a null-terminated C-style string to the ostream.
|
||||||
template <typename Char>
|
template <typename Char>
|
||||||
void PrintCStringTo(const Char* s, ostream* os) {
|
void PrintCStringTo(const Char* s, ostream* os) {
|
||||||
@ -429,7 +452,7 @@ void PrintCStringTo(const Char* s, ostream* os) {
|
|||||||
*os << "NULL";
|
*os << "NULL";
|
||||||
} else {
|
} else {
|
||||||
*os << ImplicitCast_<const void*>(s) << " pointing to ";
|
*os << ImplicitCast_<const void*>(s) << " pointing to ";
|
||||||
PrintCharsAsStringTo(s, std::char_traits<Char>::length(s), os);
|
PrintCharsAsStringTo(s, GetLength(s), os);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user