Use STL capabilities to choose GTEST_HAS_STD_WSTRING default
If the standard library claims not to support wide character strings, disable `GTEST_HAS_STD_WSTRING` and disallow users overriding it. If the standard library implementation can't be recognized, fall back to using the existing list of OSes with a known lack of support. PiperOrigin-RevId: 964237076 Change-Id: I906f296259f8f17099990d51447a0d0d04dead66
This commit is contained in:
committed by
Copybara-Service
parent
aa1eefe02c
commit
49495eacfd
@@ -500,12 +500,38 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
|
||||
#endif // defined(_MSC_VER) || defined(__BORLANDC__)
|
||||
#endif // GTEST_HAS_EXCEPTIONS
|
||||
|
||||
#ifndef GTEST_HAS_STD_WSTRING
|
||||
// The user didn't tell us whether ::std::wstring is available, so we need
|
||||
// to figure it out.
|
||||
// 1. Calculate default GTEST_HAS_STD_WSTRING values based on STL capabilities.
|
||||
#if defined(_MSVC_STL_VERSION)
|
||||
// Microsoft's STL implementation always supports ::std::wstring.
|
||||
#define GTEST_HAS_STD_WSTRING_DEFAULT 1
|
||||
|
||||
#elif defined(_LIBCPP_VERSION)
|
||||
// Modern libc++ always defines _LIBCPP_HAS_WIDE_CHARACTERS; its value
|
||||
// determines whether wide characters are supported.
|
||||
// Older libc++ omits a definition for _LIBCPP_HAS_NO_WIDE_CHARACTERS when wide
|
||||
// characters are supported.
|
||||
#if (defined(_LIBCPP_HAS_WIDE_CHARACTERS) && !_LIBCPP_HAS_WIDE_CHARACTERS) || \
|
||||
defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS)
|
||||
#define GTEST_HAS_STD_WSTRING_DEFAULT 0
|
||||
#else
|
||||
#define GTEST_HAS_STD_WSTRING_DEFAULT 1
|
||||
#endif
|
||||
|
||||
#elif defined(__GLIBCXX__)
|
||||
#if defined(_GLIBCXX_USE_WCHAR_T) && _GLIBCXX_USE_WCHAR_T
|
||||
#define GTEST_HAS_STD_WSTRING_DEFAULT 1
|
||||
#else
|
||||
#define GTEST_HAS_STD_WSTRING_DEFAULT 0
|
||||
#endif
|
||||
|
||||
#else
|
||||
// Unknown standard library implementation; fall back looking at the OS.
|
||||
//
|
||||
// Always let the user override the defaults in this case; they might have more
|
||||
// information about what's supported than we do.
|
||||
#if defined(GTEST_OS_LINUX_ANDROID)
|
||||
// Android started supporting std::wstring with API Level 21 (Lollipop).
|
||||
#define GTEST_HAS_STD_WSTRING (__ANDROID_API__ >= 21)
|
||||
#define GTEST_HAS_STD_WSTRING_DEFAULT (__ANDROID_API__ >= 21)
|
||||
// The following platforms are known not to support ::std::wstring; assume it's
|
||||
// supported on all others.
|
||||
//
|
||||
@@ -516,11 +542,29 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
|
||||
defined(GTEST_OS_ESP8266) || defined(GTEST_OS_XTENSA) || \
|
||||
defined(GTEST_OS_QURT) || defined(GTEST_OS_NXP_QN9090) || \
|
||||
defined(GTEST_OS_NRF52)
|
||||
#define GTEST_HAS_STD_WSTRING 0
|
||||
#define GTEST_HAS_STD_WSTRING_DEFAULT 0
|
||||
#else
|
||||
#define GTEST_HAS_STD_WSTRING 1
|
||||
#define GTEST_HAS_STD_WSTRING_DEFAULT 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// 2. Validate explicit user overrides (if user passed -DGTEST_HAS_*=1) against
|
||||
// what the standard library implementation tells us it supports.
|
||||
#if defined(GTEST_HAS_STD_WSTRING) && GTEST_HAS_STD_WSTRING
|
||||
#if defined(_LIBCPP_VERSION) && \
|
||||
((defined(_LIBCPP_HAS_WIDE_CHARACTERS) && !_LIBCPP_HAS_WIDE_CHARACTERS) || \
|
||||
defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS))
|
||||
#error Cannot explicitly enable GTEST_HAS_STD_WSTRING without libc++ wide character support.
|
||||
#elif defined(__GLIBCXX__) && \
|
||||
!(defined(_GLIBCXX_USE_WCHAR_T) && _GLIBCXX_USE_WCHAR_T)
|
||||
#error Cannot explicitly enable GTEST_HAS_STD_WSTRING without libstdc++ wide character support.
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// 3. Set final values if not explicitly overridden by user
|
||||
#if !defined(GTEST_HAS_STD_WSTRING)
|
||||
#define GTEST_HAS_STD_WSTRING GTEST_HAS_STD_WSTRING_DEFAULT
|
||||
#endif
|
||||
#endif // GTEST_HAS_STD_WSTRING
|
||||
|
||||
#ifndef GTEST_HAS_FILE_SYSTEM
|
||||
// Most platforms support a file system.
|
||||
|
||||
Reference in New Issue
Block a user