Path: blob/master/dep/googletest/include/gtest/internal/gtest-port.h
4808 views
// Copyright 2005, Google Inc.1// All rights reserved.2//3// Redistribution and use in source and binary forms, with or without4// modification, are permitted provided that the following conditions are5// met:6//7// * Redistributions of source code must retain the above copyright8// notice, this list of conditions and the following disclaimer.9// * Redistributions in binary form must reproduce the above10// copyright notice, this list of conditions and the following disclaimer11// in the documentation and/or other materials provided with the12// distribution.13// * Neither the name of Google Inc. nor the names of its14// contributors may be used to endorse or promote products derived from15// this software without specific prior written permission.16//17// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS18// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT19// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR20// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT21// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,22// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT23// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,24// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY25// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT26// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE27// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.2829// Low-level types and utilities for porting Google Test to various30// platforms. All macros ending with _ and symbols defined in an31// internal namespace are subject to change without notice. Code32// outside Google Test MUST NOT USE THEM DIRECTLY. Macros that don't33// end with _ are part of Google Test's public API and can be used by34// code outside Google Test.35//36// This file is fundamental to Google Test. All other Google Test source37// files are expected to #include this. Therefore, it cannot #include38// any other Google Test header.3940// IWYU pragma: private, include "gtest/gtest.h"41// IWYU pragma: friend gtest/.*42// IWYU pragma: friend gmock/.*4344#ifndef GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_45#define GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_4647// Environment-describing macros48// -----------------------------49//50// Google Test can be used in many different environments. Macros in51// this section tell Google Test what kind of environment it is being52// used in, such that Google Test can provide environment-specific53// features and implementations.54//55// Google Test tries to automatically detect the properties of its56// environment, so users usually don't need to worry about these57// macros. However, the automatic detection is not perfect.58// Sometimes it's necessary for a user to define some of the following59// macros in the build script to override Google Test's decisions.60//61// If the user doesn't define a macro in the list, Google Test will62// provide a default definition. After this header is #included, all63// macros in this list will be defined to either 1 or 0.64//65// Notes to maintainers:66// - Each macro here is a user-tweakable knob; do not grow the list67// lightly.68// - Use #if to key off these macros. Don't use #ifdef or "#if69// defined(...)", which will not work as these macros are ALWAYS70// defined.71//72// GTEST_HAS_CLONE - Define it to 1/0 to indicate that clone(2)73// is/isn't available.74// GTEST_HAS_EXCEPTIONS - Define it to 1/0 to indicate that exceptions75// are enabled.76// GTEST_HAS_POSIX_RE - Define it to 1/0 to indicate that POSIX regular77// expressions are/aren't available.78// GTEST_HAS_PTHREAD - Define it to 1/0 to indicate that <pthread.h>79// is/isn't available.80// GTEST_HAS_RTTI - Define it to 1/0 to indicate that RTTI is/isn't81// enabled.82// GTEST_HAS_STD_WSTRING - Define it to 1/0 to indicate that83// std::wstring does/doesn't work (Google Test can84// be used where std::wstring is unavailable).85// GTEST_HAS_FILE_SYSTEM - Define it to 1/0 to indicate whether or not a86// file system is/isn't available.87// GTEST_HAS_SEH - Define it to 1/0 to indicate whether the88// compiler supports Microsoft's "Structured89// Exception Handling".90// GTEST_HAS_STREAM_REDIRECTION91// - Define it to 1/0 to indicate whether the92// platform supports I/O stream redirection using93// dup() and dup2().94// GTEST_LINKED_AS_SHARED_LIBRARY95// - Define to 1 when compiling tests that use96// Google Test as a shared library (known as97// DLL on Windows).98// GTEST_CREATE_SHARED_LIBRARY99// - Define to 1 when compiling Google Test itself100// as a shared library.101// GTEST_DEFAULT_DEATH_TEST_STYLE102// - The default value of --gtest_death_test_style.103// The legacy default has been "fast" in the open104// source version since 2008. The recommended value105// is "threadsafe", and can be set in106// custom/gtest-port.h.107108// Platform-indicating macros109// --------------------------110//111// Macros indicating the platform on which Google Test is being used112// (a macro is defined to 1 if compiled on the given platform;113// otherwise UNDEFINED -- it's never defined to 0.). Google Test114// defines these macros automatically. Code outside Google Test MUST115// NOT define them.116//117// GTEST_OS_AIX - IBM AIX118// GTEST_OS_CYGWIN - Cygwin119// GTEST_OS_DRAGONFLY - DragonFlyBSD120// GTEST_OS_FREEBSD - FreeBSD121// GTEST_OS_FUCHSIA - Fuchsia122// GTEST_OS_GNU_HURD - GNU/Hurd123// GTEST_OS_GNU_KFREEBSD - GNU/kFreeBSD124// GTEST_OS_HAIKU - Haiku125// GTEST_OS_HPUX - HP-UX126// GTEST_OS_LINUX - Linux127// GTEST_OS_LINUX_ANDROID - Google Android128// GTEST_OS_MAC - Mac OS X129// GTEST_OS_IOS - iOS130// GTEST_OS_NACL - Google Native Client (NaCl)131// GTEST_OS_NETBSD - NetBSD132// GTEST_OS_OPENBSD - OpenBSD133// GTEST_OS_OS2 - OS/2134// GTEST_OS_QNX - QNX135// GTEST_OS_SOLARIS - Sun Solaris136// GTEST_OS_WINDOWS - Windows (Desktop, MinGW, or Mobile)137// GTEST_OS_WINDOWS_DESKTOP - Windows Desktop138// GTEST_OS_WINDOWS_MINGW - MinGW139// GTEST_OS_WINDOWS_MOBILE - Windows Mobile140// GTEST_OS_WINDOWS_PHONE - Windows Phone141// GTEST_OS_WINDOWS_RT - Windows Store App/WinRT142// GTEST_OS_ZOS - z/OS143//144// Among the platforms, Cygwin, Linux, Mac OS X, and Windows have the145// most stable support. Since core members of the Google Test project146// don't have access to other platforms, support for them may be less147// stable. If you notice any problems on your platform, please notify148// [email protected] (patches for fixing them are149// even more welcome!).150//151// It is possible that none of the GTEST_OS_* macros are defined.152153// Feature-indicating macros154// -------------------------155//156// Macros indicating which Google Test features are available (a macro157// is defined to 1 if the corresponding feature is supported;158// otherwise UNDEFINED -- it's never defined to 0.). Google Test159// defines these macros automatically. Code outside Google Test MUST160// NOT define them.161//162// These macros are public so that portable tests can be written.163// Such tests typically surround code using a feature with an #ifdef164// which controls that code. For example:165//166// #ifdef GTEST_HAS_DEATH_TEST167// EXPECT_DEATH(DoSomethingDeadly());168// #endif169//170// GTEST_HAS_DEATH_TEST - death tests171// GTEST_HAS_TYPED_TEST - typed tests172// GTEST_HAS_TYPED_TEST_P - type-parameterized tests173// GTEST_IS_THREADSAFE - Google Test is thread-safe.174// GTEST_USES_RE2 - the RE2 regular expression library is used175// GTEST_USES_POSIX_RE - enhanced POSIX regex is used. Do not confuse with176// GTEST_HAS_POSIX_RE (see above) which users can177// define themselves.178// GTEST_USES_SIMPLE_RE - our own simple regex is used;179// the above RE\b(s) are mutually exclusive.180// GTEST_HAS_ABSL - Google Test is compiled with Abseil.181182// Misc public macros183// ------------------184//185// GTEST_FLAG(flag_name) - references the variable corresponding to186// the given Google Test flag.187188// Internal utilities189// ------------------190//191// The following macros and utilities are for Google Test's INTERNAL192// use only. Code outside Google Test MUST NOT USE THEM DIRECTLY.193//194// Macros for basic C++ coding:195// GTEST_AMBIGUOUS_ELSE_BLOCKER_ - for disabling a gcc warning.196// GTEST_INTENTIONAL_CONST_COND_PUSH_ - start code section where MSVC C4127 is197// suppressed (constant conditional).198// GTEST_INTENTIONAL_CONST_COND_POP_ - finish code section where MSVC C4127199// is suppressed.200// GTEST_INTERNAL_HAS_ANY - for enabling UniversalPrinter<std::any> or201// UniversalPrinter<absl::any> specializations.202// Always defined to 0 or 1.203// GTEST_INTERNAL_HAS_OPTIONAL - for enabling UniversalPrinter<std::optional>204// or205// UniversalPrinter<absl::optional>206// specializations. Always defined to 0 or 1.207// GTEST_INTERNAL_HAS_STD_SPAN - for enabling UniversalPrinter<std::span>208// specializations. Always defined to 0 or 1209// GTEST_INTERNAL_HAS_STRING_VIEW - for enabling Matcher<std::string_view> or210// Matcher<absl::string_view>211// specializations. Always defined to 0 or 1.212// GTEST_INTERNAL_HAS_VARIANT - for enabling UniversalPrinter<std::variant> or213// UniversalPrinter<absl::variant>214// specializations. Always defined to 0 or 1.215// GTEST_USE_OWN_FLAGFILE_FLAG_ - Always defined to 0 or 1.216// GTEST_HAS_CXXABI_H_ - Always defined to 0 or 1.217// GTEST_CAN_STREAM_RESULTS_ - Always defined to 0 or 1.218// GTEST_HAS_ALT_PATH_SEP_ - Always defined to 0 or 1.219// GTEST_WIDE_STRING_USES_UTF16_ - Always defined to 0 or 1.220// GTEST_HAS_MUTEX_AND_THREAD_LOCAL_ - Always defined to 0 or 1.221// GTEST_HAS_NOTIFICATION_- Always defined to 0 or 1.222//223// Synchronization:224// Mutex, MutexLock, ThreadLocal, GetThreadCount()225// - synchronization primitives.226//227// Regular expressions:228// RE - a simple regular expression class using229// 1) the RE2 syntax on all platforms when built with RE2230// and Abseil as dependencies231// 2) the POSIX Extended Regular Expression syntax on232// UNIX-like platforms,233// 3) A reduced regular exception syntax on other platforms,234// including Windows.235// Logging:236// GTEST_LOG_() - logs messages at the specified severity level.237// LogToStderr() - directs all log messages to stderr.238// FlushInfoLog() - flushes informational log messages.239//240// Stdout and stderr capturing:241// CaptureStdout() - starts capturing stdout.242// GetCapturedStdout() - stops capturing stdout and returns the captured243// string.244// CaptureStderr() - starts capturing stderr.245// GetCapturedStderr() - stops capturing stderr and returns the captured246// string.247//248// Integer types:249// TypeWithSize - maps an integer to a int type.250// TimeInMillis - integers of known sizes.251// BiggestInt - the biggest signed integer type.252//253// Command-line utilities:254// GetInjectableArgvs() - returns the command line as a vector of strings.255//256// Environment variable utilities:257// GetEnv() - gets the value of an environment variable.258// BoolFromGTestEnv() - parses a bool environment variable.259// Int32FromGTestEnv() - parses an int32_t environment variable.260// StringFromGTestEnv() - parses a string environment variable.261262// The definition of GTEST_INTERNAL_CPLUSPLUS_LANG comes first because it can263// potentially be used as an #include guard.264#if defined(_MSVC_LANG)265#define GTEST_INTERNAL_CPLUSPLUS_LANG _MSVC_LANG266#elif defined(__cplusplus)267#define GTEST_INTERNAL_CPLUSPLUS_LANG __cplusplus268#endif269270#if !defined(GTEST_INTERNAL_CPLUSPLUS_LANG) || \271GTEST_INTERNAL_CPLUSPLUS_LANG < 201703L272#error C++ versions less than C++17 are not supported.273#endif274275// MSVC >= 19.11 (VS 2017 Update 3) supports __has_include.276#ifdef __has_include277#define GTEST_INTERNAL_HAS_INCLUDE __has_include278#else279#define GTEST_INTERNAL_HAS_INCLUDE(...) 0280#endif281282// Detect C++ feature test macros as gracefully as possible.283// MSVC >= 19.15, Clang >= 3.4.1, and GCC >= 4.1.2 support feature test macros.284//285// GCC15 warns that <ciso646> is deprecated in C++17 and suggests using286// <version> instead, even though <version> is not available in C++17 mode prior287// to GCC9.288#if GTEST_INTERNAL_CPLUSPLUS_LANG >= 202002L || \289GTEST_INTERNAL_HAS_INCLUDE(<version>)290#include <version> // C++20 or <version> support.291#else292#include <ciso646> // Pre-C++20293#endif294295#include <ctype.h> // for isspace, etc296#include <stddef.h> // for ptrdiff_t297#include <stdio.h>298#include <stdlib.h>299#include <string.h>300301#include <cerrno>302// #include <condition_variable> // Guarded by GTEST_IS_THREADSAFE below303#include <cstdint>304#include <iostream>305#include <limits>306#include <locale>307#include <memory>308#include <ostream>309#include <string>310// #include <mutex> // Guarded by GTEST_IS_THREADSAFE below311#include <tuple>312#include <type_traits>313#include <vector>314315#ifndef _WIN32_WCE316#include <sys/stat.h>317#include <sys/types.h>318#endif // !_WIN32_WCE319320#if defined __APPLE__321#include <AvailabilityMacros.h>322#include <TargetConditionals.h>323#endif324325#include "gtest/internal/custom/gtest-port.h"326#include "gtest/internal/gtest-port-arch.h"327328#ifndef GTEST_HAS_MUTEX_AND_THREAD_LOCAL_329#define GTEST_HAS_MUTEX_AND_THREAD_LOCAL_ 0330#endif331332#ifndef GTEST_HAS_NOTIFICATION_333#define GTEST_HAS_NOTIFICATION_ 0334#endif335336#if defined(GTEST_HAS_ABSL) && !defined(GTEST_NO_ABSL_FLAGS)337#define GTEST_INTERNAL_HAS_ABSL_FLAGS // Used only in this file.338#include "absl/flags/declare.h"339#include "absl/flags/flag.h"340#include "absl/flags/reflection.h"341#endif342343#if !defined(GTEST_DEV_EMAIL_)344#define GTEST_DEV_EMAIL_ "googletestframework@@googlegroups.com"345#define GTEST_FLAG_PREFIX_ "gtest_"346#define GTEST_FLAG_PREFIX_DASH_ "gtest-"347#define GTEST_FLAG_PREFIX_UPPER_ "GTEST_"348#define GTEST_NAME_ "Google Test"349#define GTEST_PROJECT_URL_ "https://github.com/google/googletest/"350#endif // !defined(GTEST_DEV_EMAIL_)351352#if !defined(GTEST_INIT_GOOGLE_TEST_NAME_)353#define GTEST_INIT_GOOGLE_TEST_NAME_ "testing::InitGoogleTest"354#endif // !defined(GTEST_INIT_GOOGLE_TEST_NAME_)355356// Determines the version of gcc that is used to compile this.357#ifdef __GNUC__358// 40302 means version 4.3.2.359#define GTEST_GCC_VER_ \360(__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)361#endif // __GNUC__362363// Macros for disabling Microsoft Visual C++ warnings.364//365// GTEST_DISABLE_MSC_WARNINGS_PUSH_(4800 4385)366// /* code that triggers warnings C4800 and C4385 */367// GTEST_DISABLE_MSC_WARNINGS_POP_()368#if defined(_MSC_VER)369#define GTEST_DISABLE_MSC_WARNINGS_PUSH_(warnings) \370__pragma(warning(push)) __pragma(warning(disable : warnings))371#define GTEST_DISABLE_MSC_WARNINGS_POP_() __pragma(warning(pop))372#else373// Not all compilers are MSVC374#define GTEST_DISABLE_MSC_WARNINGS_PUSH_(warnings)375#define GTEST_DISABLE_MSC_WARNINGS_POP_()376#endif377378// Clang on Windows does not understand MSVC's pragma warning.379// We need clang-specific way to disable function deprecation warning.380#ifdef __clang__381#define GTEST_DISABLE_MSC_DEPRECATED_PUSH_() \382_Pragma("clang diagnostic push") \383_Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"") \384_Pragma("clang diagnostic ignored \"-Wdeprecated-implementations\"")385#define GTEST_DISABLE_MSC_DEPRECATED_POP_() _Pragma("clang diagnostic pop")386#else387#define GTEST_DISABLE_MSC_DEPRECATED_PUSH_() \388GTEST_DISABLE_MSC_WARNINGS_PUSH_(4996)389#define GTEST_DISABLE_MSC_DEPRECATED_POP_() GTEST_DISABLE_MSC_WARNINGS_POP_()390#endif391392// Brings in definitions for functions used in the testing::internal::posix393// namespace (read, write, close, chdir, isatty, stat). We do not currently394// use them on Windows Mobile.395#ifdef GTEST_OS_WINDOWS396#ifndef GTEST_OS_WINDOWS_MOBILE397#include <direct.h>398#include <io.h>399#endif400// In order to avoid having to include <windows.h>, use forward declaration401#if defined(GTEST_OS_WINDOWS_MINGW) && !defined(__MINGW64_VERSION_MAJOR)402// MinGW defined _CRITICAL_SECTION and _RTL_CRITICAL_SECTION as two403// separate (equivalent) structs, instead of using typedef404typedef struct _CRITICAL_SECTION GTEST_CRITICAL_SECTION;405#else406// Assume CRITICAL_SECTION is a typedef of _RTL_CRITICAL_SECTION.407// This assumption is verified by408// WindowsTypesTest.CRITICAL_SECTIONIs_RTL_CRITICAL_SECTION.409typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;410#endif411#elif defined(GTEST_OS_XTENSA)412#include <unistd.h>413// Xtensa toolchains define strcasecmp in the string.h header instead of414// strings.h. string.h is already included.415#else416// This assumes that non-Windows OSes provide unistd.h. For OSes where this417// is not the case, we need to include headers that provide the functions418// mentioned above.419#include <strings.h>420#include <unistd.h>421#endif // GTEST_OS_WINDOWS422423#ifdef GTEST_OS_LINUX_ANDROID424// Used to define __ANDROID_API__ matching the target NDK API level.425#include <android/api-level.h> // NOLINT426#endif427428// Defines this to true if and only if Google Test can use POSIX regular429// expressions.430#ifndef GTEST_HAS_POSIX_RE431#ifdef GTEST_OS_LINUX_ANDROID432// On Android, <regex.h> is only available starting with Gingerbread.433#define GTEST_HAS_POSIX_RE (__ANDROID_API__ >= 9)434#else435#if !(defined(GTEST_OS_WINDOWS) || defined(GTEST_OS_XTENSA) || \436defined(GTEST_OS_QURT))437#define GTEST_HAS_POSIX_RE 1438#else439#define GTEST_HAS_POSIX_RE 0440#endif441#endif // GTEST_OS_LINUX_ANDROID442#endif443444// Select the regular expression implementation.445#ifdef GTEST_HAS_ABSL446// When using Abseil, RE2 is required.447#include "absl/strings/string_view.h"448#include "re2/re2.h"449#define GTEST_USES_RE2 1450#elif GTEST_HAS_POSIX_RE451#include <regex.h> // NOLINT452#define GTEST_USES_POSIX_RE 1453#else454// Use our own simple regex implementation.455#define GTEST_USES_SIMPLE_RE 1456#endif457458#ifndef GTEST_HAS_EXCEPTIONS459// The user didn't tell us whether exceptions are enabled, so we need460// to figure it out.461#if defined(_MSC_VER) && defined(_CPPUNWIND)462// MSVC defines _CPPUNWIND to 1 if and only if exceptions are enabled.463#define GTEST_HAS_EXCEPTIONS 1464#elif defined(__BORLANDC__)465// C++Builder's implementation of the STL uses the _HAS_EXCEPTIONS466// macro to enable exceptions, so we'll do the same.467// Assumes that exceptions are enabled by default.468#ifndef _HAS_EXCEPTIONS469#define _HAS_EXCEPTIONS 1470#endif // _HAS_EXCEPTIONS471#define GTEST_HAS_EXCEPTIONS _HAS_EXCEPTIONS472#elif defined(__clang__)473// clang defines __EXCEPTIONS if and only if exceptions are enabled before clang474// 220714, but if and only if cleanups are enabled after that. In Obj-C++ files,475// there can be cleanups for ObjC exceptions which also need cleanups, even if476// C++ exceptions are disabled. clang has __has_feature(cxx_exceptions) which477// checks for C++ exceptions starting at clang r206352, but which checked for478// cleanups prior to that. To reliably check for C++ exception availability with479// clang, check for480// __EXCEPTIONS && __has_feature(cxx_exceptions).481#if defined(__EXCEPTIONS) && __EXCEPTIONS && __has_feature(cxx_exceptions)482#define GTEST_HAS_EXCEPTIONS 1483#else484#define GTEST_HAS_EXCEPTIONS 0485#endif486#elif defined(__GNUC__) && defined(__EXCEPTIONS) && __EXCEPTIONS487// gcc defines __EXCEPTIONS to 1 if and only if exceptions are enabled.488#define GTEST_HAS_EXCEPTIONS 1489#elif defined(__SUNPRO_CC)490// Sun Pro CC supports exceptions. However, there is no compile-time way of491// detecting whether they are enabled or not. Therefore, we assume that492// they are enabled unless the user tells us otherwise.493#define GTEST_HAS_EXCEPTIONS 1494#elif defined(__IBMCPP__) && defined(__EXCEPTIONS) && __EXCEPTIONS495// xlC defines __EXCEPTIONS to 1 if and only if exceptions are enabled.496#define GTEST_HAS_EXCEPTIONS 1497#elif defined(__HP_aCC)498// Exception handling is in effect by default in HP aCC compiler. It has to499// be turned of by +noeh compiler option if desired.500#define GTEST_HAS_EXCEPTIONS 1501#else502// For other compilers, we assume exceptions are disabled to be503// conservative.504#define GTEST_HAS_EXCEPTIONS 0505#endif // defined(_MSC_VER) || defined(__BORLANDC__)506#endif // GTEST_HAS_EXCEPTIONS507508#ifndef GTEST_HAS_STD_WSTRING509// The user didn't tell us whether ::std::wstring is available, so we need510// to figure it out.511// Cygwin 1.7 and below doesn't support ::std::wstring.512// Solaris' libc++ doesn't support it either. Android has513// no support for it at least as recent as Froyo (2.2).514#if (!(defined(GTEST_OS_LINUX_ANDROID) || defined(GTEST_OS_CYGWIN) || \515defined(GTEST_OS_SOLARIS) || defined(GTEST_OS_HAIKU) || \516defined(GTEST_OS_ESP32) || defined(GTEST_OS_ESP8266) || \517defined(GTEST_OS_XTENSA) || defined(GTEST_OS_QURT) || \518defined(GTEST_OS_NXP_QN9090) || defined(GTEST_OS_NRF52)))519#define GTEST_HAS_STD_WSTRING 1520#else521#define GTEST_HAS_STD_WSTRING 0522#endif523#endif // GTEST_HAS_STD_WSTRING524525#ifndef GTEST_HAS_FILE_SYSTEM526// Most platforms support a file system.527#define GTEST_HAS_FILE_SYSTEM 1528#endif // GTEST_HAS_FILE_SYSTEM529530// Determines whether RTTI is available.531#ifndef GTEST_HAS_RTTI532// The user didn't tell us whether RTTI is enabled, so we need to533// figure it out.534535#ifdef _MSC_VER536537#ifdef _CPPRTTI // MSVC defines this macro if and only if RTTI is enabled.538#define GTEST_HAS_RTTI 1539#else540#define GTEST_HAS_RTTI 0541#endif542543// Starting with version 4.3.2, gcc defines __GXX_RTTI if and only if RTTI is544// enabled.545#elif defined(__GNUC__)546547#ifdef __GXX_RTTI548// When building against STLport with the Android NDK and with549// -frtti -fno-exceptions, the build fails at link time with undefined550// references to __cxa_bad_typeid. Note sure if STL or toolchain bug,551// so disable RTTI when detected.552#if defined(GTEST_OS_LINUX_ANDROID) && defined(_STLPORT_MAJOR) && \553!defined(__EXCEPTIONS)554#define GTEST_HAS_RTTI 0555#else556#define GTEST_HAS_RTTI 1557#endif // GTEST_OS_LINUX_ANDROID && __STLPORT_MAJOR && !__EXCEPTIONS558#else559#define GTEST_HAS_RTTI 0560#endif // __GXX_RTTI561562// Clang defines __GXX_RTTI starting with version 3.0, but its manual recommends563// using has_feature instead. has_feature(cxx_rtti) is supported since 2.7, the564// first version with C++ support.565#elif defined(__clang__)566567#define GTEST_HAS_RTTI __has_feature(cxx_rtti)568569// Starting with version 9.0 IBM Visual Age defines __RTTI_ALL__ to 1 if570// both the typeid and dynamic_cast features are present.571#elif defined(__IBMCPP__) && (__IBMCPP__ >= 900)572573#ifdef __RTTI_ALL__574#define GTEST_HAS_RTTI 1575#else576#define GTEST_HAS_RTTI 0577#endif578579#else580581// For all other compilers, we assume RTTI is enabled.582#define GTEST_HAS_RTTI 1583584#endif // _MSC_VER585586#endif // GTEST_HAS_RTTI587588// It's this header's responsibility to #include <typeinfo> when RTTI589// is enabled.590#if GTEST_HAS_RTTI591#include <typeinfo>592#endif593594// Determines whether Google Test can use the pthreads library.595#ifndef GTEST_HAS_PTHREAD596// The user didn't tell us explicitly, so we make reasonable assumptions about597// which platforms have pthreads support.598//599// To disable threading support in Google Test, add -DGTEST_HAS_PTHREAD=0600// to your compiler flags.601#if (defined(GTEST_OS_LINUX) || defined(GTEST_OS_MAC) || \602defined(GTEST_OS_HPUX) || defined(GTEST_OS_QNX) || \603defined(GTEST_OS_FREEBSD) || defined(GTEST_OS_NACL) || \604defined(GTEST_OS_NETBSD) || defined(GTEST_OS_FUCHSIA) || \605defined(GTEST_OS_DRAGONFLY) || defined(GTEST_OS_GNU_KFREEBSD) || \606defined(GTEST_OS_OPENBSD) || defined(GTEST_OS_HAIKU) || \607defined(GTEST_OS_GNU_HURD) || defined(GTEST_OS_SOLARIS) || \608defined(GTEST_OS_AIX) || defined(GTEST_OS_ZOS))609#define GTEST_HAS_PTHREAD 1610#else611#define GTEST_HAS_PTHREAD 0612#endif613#endif // GTEST_HAS_PTHREAD614615#if GTEST_HAS_PTHREAD616// gtest-port.h guarantees to #include <pthread.h> when GTEST_HAS_PTHREAD is617// true.618#include <pthread.h> // NOLINT619620// For timespec and nanosleep, used below.621#include <time.h> // NOLINT622#endif623624// Determines whether clone(2) is supported.625// Usually it will only be available on Linux, excluding626// Linux on the Itanium architecture.627// Also see https://linux.die.net/man/2/clone.628#ifndef GTEST_HAS_CLONE629// The user didn't tell us, so we need to figure it out.630631#if defined(GTEST_OS_LINUX) && !defined(__ia64__)632#if defined(GTEST_OS_LINUX_ANDROID)633// On Android, clone() became available at different API levels for each 32-bit634// architecture.635#if defined(__LP64__) || (defined(__arm__) && __ANDROID_API__ >= 9) || \636(defined(__mips__) && __ANDROID_API__ >= 12) || \637(defined(__i386__) && __ANDROID_API__ >= 17)638#define GTEST_HAS_CLONE 1639#else640#define GTEST_HAS_CLONE 0641#endif642#else643#define GTEST_HAS_CLONE 1644#endif645#else646#define GTEST_HAS_CLONE 0647#endif // GTEST_OS_LINUX && !defined(__ia64__)648649#endif // GTEST_HAS_CLONE650651// Determines whether to support stream redirection. This is used to test652// output correctness and to implement death tests.653#ifndef GTEST_HAS_STREAM_REDIRECTION654// By default, we assume that stream redirection is supported on all655// platforms except known mobile / embedded ones. Also, if the port doesn't have656// a file system, stream redirection is not supported.657#if defined(GTEST_OS_WINDOWS_MOBILE) || defined(GTEST_OS_WINDOWS_PHONE) || \658defined(GTEST_OS_WINDOWS_RT) || defined(GTEST_OS_WINDOWS_GAMES) || \659defined(GTEST_OS_ESP8266) || defined(GTEST_OS_XTENSA) || \660defined(GTEST_OS_QURT) || !GTEST_HAS_FILE_SYSTEM661#define GTEST_HAS_STREAM_REDIRECTION 0662#else663#define GTEST_HAS_STREAM_REDIRECTION 1664#endif // !GTEST_OS_WINDOWS_MOBILE665#endif // GTEST_HAS_STREAM_REDIRECTION666667// Determines whether to support death tests.668// pops up a dialog window that cannot be suppressed programmatically.669#if (defined(GTEST_OS_LINUX) || defined(GTEST_OS_CYGWIN) || \670defined(GTEST_OS_SOLARIS) || defined(GTEST_OS_ZOS) || \671(defined(GTEST_OS_MAC) && !defined(GTEST_OS_IOS)) || \672(defined(GTEST_OS_WINDOWS_DESKTOP) && _MSC_VER) || \673defined(GTEST_OS_WINDOWS_MINGW) || defined(GTEST_OS_AIX) || \674defined(GTEST_OS_HPUX) || defined(GTEST_OS_OPENBSD) || \675defined(GTEST_OS_QNX) || defined(GTEST_OS_FREEBSD) || \676defined(GTEST_OS_NETBSD) || defined(GTEST_OS_FUCHSIA) || \677defined(GTEST_OS_DRAGONFLY) || defined(GTEST_OS_GNU_KFREEBSD) || \678defined(GTEST_OS_HAIKU) || defined(GTEST_OS_GNU_HURD))679// Death tests require a file system to work properly.680#if GTEST_HAS_FILE_SYSTEM681#define GTEST_HAS_DEATH_TEST 1682#endif // GTEST_HAS_FILE_SYSTEM683#endif684685// Determines whether to support type-driven tests.686687// Typed tests need <typeinfo> and variadic macros, which GCC, VC++ 8.0,688// Sun Pro CC, IBM Visual Age, and HP aCC support.689#if defined(__GNUC__) || defined(_MSC_VER) || defined(__SUNPRO_CC) || \690defined(__IBMCPP__) || defined(__HP_aCC)691#define GTEST_HAS_TYPED_TEST 1692#define GTEST_HAS_TYPED_TEST_P 1693#endif694695// Determines whether the system compiler uses UTF-16 for encoding wide strings.696#if defined(GTEST_OS_WINDOWS) || defined(GTEST_OS_CYGWIN) || \697defined(GTEST_OS_AIX) || defined(GTEST_OS_OS2)698#define GTEST_WIDE_STRING_USES_UTF16_ 1699#else700#define GTEST_WIDE_STRING_USES_UTF16_ 0701#endif702703// Determines whether test results can be streamed to a socket.704#if defined(GTEST_OS_LINUX) || defined(GTEST_OS_GNU_KFREEBSD) || \705defined(GTEST_OS_DRAGONFLY) || defined(GTEST_OS_FREEBSD) || \706defined(GTEST_OS_NETBSD) || defined(GTEST_OS_OPENBSD) || \707defined(GTEST_OS_GNU_HURD) || defined(GTEST_OS_MAC)708#define GTEST_CAN_STREAM_RESULTS_ 1709#else710#define GTEST_CAN_STREAM_RESULTS_ 0711#endif712713// Defines some utility macros.714715// The GNU compiler emits a warning if nested "if" statements are followed by716// an "else" statement and braces are not used to explicitly disambiguate the717// "else" binding. This leads to problems with code like:718//719// if (gate)720// ASSERT_*(condition) << "Some message";721//722// The "switch (0) case 0:" idiom is used to suppress this.723#ifdef __INTEL_COMPILER724#define GTEST_AMBIGUOUS_ELSE_BLOCKER_725#else726#define GTEST_AMBIGUOUS_ELSE_BLOCKER_ \727switch (0) \728case 0: \729default: // NOLINT730#endif731732// GTEST_HAVE_ATTRIBUTE_733//734// A function-like feature checking macro that is a wrapper around735// `__has_attribute`, which is defined by GCC 5+ and Clang and evaluates to a736// nonzero constant integer if the attribute is supported or 0 if not.737//738// It evaluates to zero if `__has_attribute` is not defined by the compiler.739//740// GCC: https://gcc.gnu.org/gcc-5/changes.html741// Clang: https://clang.llvm.org/docs/LanguageExtensions.html742#ifdef __has_attribute743#define GTEST_HAVE_ATTRIBUTE_(x) __has_attribute(x)744#else745#define GTEST_HAVE_ATTRIBUTE_(x) 0746#endif747748// GTEST_INTERNAL_HAVE_CPP_ATTRIBUTE749//750// A function-like feature checking macro that accepts C++11 style attributes.751// It's a wrapper around `__has_cpp_attribute`, defined by ISO C++ SD-6752// (https://en.cppreference.com/w/cpp/experimental/feature_test). If we don't753// find `__has_cpp_attribute`, will evaluate to 0.754#if defined(__has_cpp_attribute)755// NOTE: requiring __cplusplus above should not be necessary, but756// works around https://bugs.llvm.org/show_bug.cgi?id=23435.757#define GTEST_INTERNAL_HAVE_CPP_ATTRIBUTE(x) __has_cpp_attribute(x)758#else759#define GTEST_INTERNAL_HAVE_CPP_ATTRIBUTE(x) 0760#endif761762// GTEST_HAVE_FEATURE_763//764// A function-like feature checking macro that is a wrapper around765// `__has_feature`.766#ifdef __has_feature767#define GTEST_HAVE_FEATURE_(x) __has_feature(x)768#else769#define GTEST_HAVE_FEATURE_(x) 0770#endif771772// Use this annotation before a function that takes a printf format string.773#if GTEST_HAVE_ATTRIBUTE_(format) && defined(__MINGW_PRINTF_FORMAT)774// MinGW has two different printf implementations. Ensure the format macro775// matches the selected implementation. See776// https://sourceforge.net/p/mingw-w64/wiki2/gnu%20printf/.777#define GTEST_ATTRIBUTE_PRINTF_(string_index, first_to_check) \778__attribute__((format(__MINGW_PRINTF_FORMAT, string_index, first_to_check)))779#elif GTEST_HAVE_ATTRIBUTE_(format)780#define GTEST_ATTRIBUTE_PRINTF_(string_index, first_to_check) \781__attribute__((format(printf, string_index, first_to_check)))782#else783#define GTEST_ATTRIBUTE_PRINTF_(string_index, first_to_check)784#endif785786// MS C++ compiler emits warning when a conditional expression is compile time787// constant. In some contexts this warning is false positive and needs to be788// suppressed. Use the following two macros in such cases:789//790// GTEST_INTENTIONAL_CONST_COND_PUSH_()791// while (true) {792// GTEST_INTENTIONAL_CONST_COND_POP_()793// }794#define GTEST_INTENTIONAL_CONST_COND_PUSH_() \795GTEST_DISABLE_MSC_WARNINGS_PUSH_(4127)796#define GTEST_INTENTIONAL_CONST_COND_POP_() GTEST_DISABLE_MSC_WARNINGS_POP_()797798// Determine whether the compiler supports Microsoft's Structured Exception799// Handling. This is supported by several Windows compilers but generally800// does not exist on any other system.801#ifndef GTEST_HAS_SEH802// The user didn't tell us, so we need to figure it out.803804#if defined(_MSC_VER) || defined(__BORLANDC__)805// These two compilers are known to support SEH.806#define GTEST_HAS_SEH 1807#else808// Assume no SEH.809#define GTEST_HAS_SEH 0810#endif811812#endif // GTEST_HAS_SEH813814#ifndef GTEST_IS_THREADSAFE815816#if (GTEST_HAS_MUTEX_AND_THREAD_LOCAL_ || \817(defined(GTEST_OS_WINDOWS) && !defined(GTEST_OS_WINDOWS_PHONE) && \818!defined(GTEST_OS_WINDOWS_RT)) || \819GTEST_HAS_PTHREAD)820#define GTEST_IS_THREADSAFE 1821#endif822823#endif // GTEST_IS_THREADSAFE824825#ifdef GTEST_IS_THREADSAFE826// Some platforms don't support including these threading related headers.827#include <condition_variable> // NOLINT828#include <mutex> // NOLINT829#endif // GTEST_IS_THREADSAFE830831// GTEST_API_ qualifies all symbols that must be exported. The definitions below832// are guarded by #ifndef to give embedders a chance to define GTEST_API_ in833// gtest/internal/custom/gtest-port.h834#ifndef GTEST_API_835836#ifdef _MSC_VER837#if defined(GTEST_LINKED_AS_SHARED_LIBRARY) && GTEST_LINKED_AS_SHARED_LIBRARY838#define GTEST_API_ __declspec(dllimport)839#elif defined(GTEST_CREATE_SHARED_LIBRARY) && GTEST_CREATE_SHARED_LIBRARY840#define GTEST_API_ __declspec(dllexport)841#endif842#elif GTEST_HAVE_ATTRIBUTE_(visibility)843#define GTEST_API_ __attribute__((visibility("default")))844#endif // _MSC_VER845846#endif // GTEST_API_847848#ifndef GTEST_API_849#define GTEST_API_850#endif // GTEST_API_851852#ifndef GTEST_DEFAULT_DEATH_TEST_STYLE853#define GTEST_DEFAULT_DEATH_TEST_STYLE "fast"854#endif // GTEST_DEFAULT_DEATH_TEST_STYLE855856#if GTEST_HAVE_ATTRIBUTE_(noinline)857// Ask the compiler to never inline a given function.858#define GTEST_NO_INLINE_ __attribute__((noinline))859#else860#define GTEST_NO_INLINE_861#endif862863#if GTEST_HAVE_ATTRIBUTE_(disable_tail_calls)864// Ask the compiler not to perform tail call optimization inside865// the marked function.866#define GTEST_NO_TAIL_CALL_ __attribute__((disable_tail_calls))867#elif defined(__GNUC__) && !defined(__NVCOMPILER)868#define GTEST_NO_TAIL_CALL_ \869__attribute__((optimize("no-optimize-sibling-calls")))870#else871#define GTEST_NO_TAIL_CALL_872#endif873874// _LIBCPP_VERSION is defined by the libc++ library from the LLVM project.875#if !defined(GTEST_HAS_CXXABI_H_)876#if defined(__GLIBCXX__) || (defined(_LIBCPP_VERSION) && !defined(_MSC_VER))877#define GTEST_HAS_CXXABI_H_ 1878#else879#define GTEST_HAS_CXXABI_H_ 0880#endif881#endif882883// A function level attribute to disable checking for use of uninitialized884// memory when built with MemorySanitizer.885#if GTEST_HAVE_ATTRIBUTE_(no_sanitize_memory)886#define GTEST_ATTRIBUTE_NO_SANITIZE_MEMORY_ __attribute__((no_sanitize_memory))887#else888#define GTEST_ATTRIBUTE_NO_SANITIZE_MEMORY_889#endif890891// A function level attribute to disable AddressSanitizer instrumentation.892#if GTEST_HAVE_ATTRIBUTE_(no_sanitize_address)893#define GTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS_ \894__attribute__((no_sanitize_address))895#else896#define GTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS_897#endif898899// A function level attribute to disable HWAddressSanitizer instrumentation.900#if GTEST_HAVE_FEATURE_(hwaddress_sanitizer) && \901GTEST_HAVE_ATTRIBUTE_(no_sanitize)902#define GTEST_ATTRIBUTE_NO_SANITIZE_HWADDRESS_ \903__attribute__((no_sanitize("hwaddress")))904#else905#define GTEST_ATTRIBUTE_NO_SANITIZE_HWADDRESS_906#endif907908// A function level attribute to disable ThreadSanitizer instrumentation.909#if GTEST_HAVE_ATTRIBUTE_(no_sanitize_thread)910#define GTEST_ATTRIBUTE_NO_SANITIZE_THREAD_ __attribute((no_sanitize_thread))911#else912#define GTEST_ATTRIBUTE_NO_SANITIZE_THREAD_913#endif914915namespace testing {916917class Message;918919// Legacy imports for backwards compatibility.920// New code should use std:: names directly.921using std::get;922using std::make_tuple;923using std::tuple;924using std::tuple_element;925using std::tuple_size;926927namespace internal {928929// A secret type that Google Test users don't know about. It has no930// accessible constructors on purpose. Therefore it's impossible to create a931// Secret object, which is what we want.932class Secret {933Secret(const Secret&) = delete;934};935936// A helper for suppressing warnings on constant condition. It just937// returns 'condition'.938GTEST_API_ bool IsTrue(bool condition);939940// Defines RE.941942#ifdef GTEST_USES_RE2943944// This is almost `using RE = ::RE2`, except it is copy-constructible, and it945// needs to disambiguate the `std::string`, `absl::string_view`, and `const946// char*` constructors.947class GTEST_API_ RE {948public:949RE(absl::string_view regex) : regex_(regex) {} // NOLINT950RE(const char* regex) : RE(absl::string_view(regex)) {} // NOLINT951RE(const std::string& regex) : RE(absl::string_view(regex)) {} // NOLINT952RE(const RE& other) : RE(other.pattern()) {}953954const std::string& pattern() const { return regex_.pattern(); }955956static bool FullMatch(absl::string_view str, const RE& re) {957return RE2::FullMatch(str, re.regex_);958}959static bool PartialMatch(absl::string_view str, const RE& re) {960return RE2::PartialMatch(str, re.regex_);961}962963private:964RE2 regex_;965};966967#elif defined(GTEST_USES_POSIX_RE) || defined(GTEST_USES_SIMPLE_RE)968GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \969/* class A needs to have dll-interface to be used by clients of class B */)970971// A simple C++ wrapper for <regex.h>. It uses the POSIX Extended972// Regular Expression syntax.973class GTEST_API_ RE {974public:975// A copy constructor is required by the Standard to initialize object976// references from r-values.977RE(const RE& other) { Init(other.pattern()); }978979// Constructs an RE from a string.980RE(const ::std::string& regex) { Init(regex.c_str()); } // NOLINT981982RE(const char* regex) { Init(regex); } // NOLINT983~RE();984985// Returns the string representation of the regex.986const char* pattern() const { return pattern_.c_str(); }987988// FullMatch(str, re) returns true if and only if regular expression re989// matches the entire str.990// PartialMatch(str, re) returns true if and only if regular expression re991// matches a substring of str (including str itself).992static bool FullMatch(const ::std::string& str, const RE& re) {993return FullMatch(str.c_str(), re);994}995static bool PartialMatch(const ::std::string& str, const RE& re) {996return PartialMatch(str.c_str(), re);997}998999static bool FullMatch(const char* str, const RE& re);1000static bool PartialMatch(const char* str, const RE& re);10011002private:1003void Init(const char* regex);1004std::string pattern_;1005bool is_valid_;10061007#ifdef GTEST_USES_POSIX_RE10081009regex_t full_regex_; // For FullMatch().1010regex_t partial_regex_; // For PartialMatch().10111012#else // GTEST_USES_SIMPLE_RE10131014std::string full_pattern_; // For FullMatch();10151016#endif1017};1018GTEST_DISABLE_MSC_WARNINGS_POP_() // 42511019#endif // ::testing::internal::RE implementation10201021// Formats a source file path and a line number as they would appear1022// in an error message from the compiler used to compile this code.1023GTEST_API_ ::std::string FormatFileLocation(const char* file, int line);10241025// Formats a file location for compiler-independent XML output.1026// Although this function is not platform dependent, we put it next to1027// FormatFileLocation in order to contrast the two functions.1028GTEST_API_ ::std::string FormatCompilerIndependentFileLocation(const char* file,1029int line);10301031// Defines logging utilities:1032// GTEST_LOG_(severity) - logs messages at the specified severity level. The1033// message itself is streamed into the macro.1034// LogToStderr() - directs all log messages to stderr.1035// FlushInfoLog() - flushes informational log messages.10361037enum GTestLogSeverity { GTEST_INFO, GTEST_WARNING, GTEST_ERROR, GTEST_FATAL };10381039// Formats log entry severity, provides a stream object for streaming the1040// log message, and terminates the message with a newline when going out of1041// scope.1042class GTEST_API_ GTestLog {1043public:1044GTestLog(GTestLogSeverity severity, const char* file, int line);10451046// Flushes the buffers and, if severity is GTEST_FATAL, aborts the program.1047~GTestLog();10481049::std::ostream& GetStream() { return ::std::cerr; }10501051private:1052const GTestLogSeverity severity_;10531054GTestLog(const GTestLog&) = delete;1055GTestLog& operator=(const GTestLog&) = delete;1056};10571058#if !defined(GTEST_LOG_)10591060#define GTEST_LOG_(severity) \1061::testing::internal::GTestLog(::testing::internal::GTEST_##severity, \1062__FILE__, __LINE__) \1063.GetStream()10641065inline void LogToStderr() {}1066inline void FlushInfoLog() { fflush(nullptr); }10671068#endif // !defined(GTEST_LOG_)10691070#if !defined(GTEST_CHECK_)1071// INTERNAL IMPLEMENTATION - DO NOT USE.1072//1073// GTEST_CHECK_ is an all-mode assert. It aborts the program if the condition1074// is not satisfied.1075// Synopsis:1076// GTEST_CHECK_(boolean_condition);1077// or1078// GTEST_CHECK_(boolean_condition) << "Additional message";1079//1080// This checks the condition and if the condition is not satisfied1081// it prints message about the condition violation, including the1082// condition itself, plus additional message streamed into it, if any,1083// and then it aborts the program. It aborts the program irrespective of1084// whether it is built in the debug mode or not.1085#define GTEST_CHECK_(condition) \1086GTEST_AMBIGUOUS_ELSE_BLOCKER_ \1087if (::testing::internal::IsTrue(condition)) \1088; \1089else \1090GTEST_LOG_(FATAL) << "Condition " #condition " failed. "1091#endif // !defined(GTEST_CHECK_)10921093// An all-mode assert to verify that the given POSIX-style function1094// call returns 0 (indicating success). Known limitation: this1095// doesn't expand to a balanced 'if' statement, so enclose the macro1096// in {} if you need to use it as the only statement in an 'if'1097// branch.1098#define GTEST_CHECK_POSIX_SUCCESS_(posix_call) \1099if (const int gtest_error = (posix_call)) \1100GTEST_LOG_(FATAL) << #posix_call << "failed with error " << gtest_error11011102// Transforms "T" into "const T&" according to standard reference collapsing1103// rules (this is only needed as a backport for C++98 compilers that do not1104// support reference collapsing). Specifically, it transforms:1105//1106// char ==> const char&1107// const char ==> const char&1108// char& ==> char&1109// const char& ==> const char&1110//1111// Note that the non-const reference will not have "const" added. This is1112// standard, and necessary so that "T" can always bind to "const T&".1113template <typename T>1114struct ConstRef {1115typedef const T& type;1116};1117template <typename T>1118struct ConstRef<T&> {1119typedef T& type;1120};11211122// The argument T must depend on some template parameters.1123#define GTEST_REFERENCE_TO_CONST_(T) \1124typename ::testing::internal::ConstRef<T>::type11251126// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.1127//1128// Use ImplicitCast_ as a safe version of static_cast for upcasting in1129// the type hierarchy (e.g. casting a Foo* to a SuperclassOfFoo* or a1130// const Foo*). When you use ImplicitCast_, the compiler checks that1131// the cast is safe. Such explicit ImplicitCast_s are necessary in1132// surprisingly many situations where C++ demands an exact type match1133// instead of an argument type convertible to a target type.1134//1135// The syntax for using ImplicitCast_ is the same as for static_cast:1136//1137// ImplicitCast_<ToType>(expr)1138//1139// ImplicitCast_ would have been part of the C++ standard library,1140// but the proposal was submitted too late. It will probably make1141// its way into the language in the future.1142//1143// This relatively ugly name is intentional. It prevents clashes with1144// similar functions users may have (e.g., implicit_cast). The internal1145// namespace alone is not enough because the function can be found by ADL.1146template <typename To>1147inline To ImplicitCast_(To x) {1148return x;1149}11501151// Downcasts the pointer of type Base to Derived.1152// Derived must be a subclass of Base. The parameter MUST1153// point to a class of type Derived, not any subclass of it.1154// When RTTI is available, the function performs a runtime1155// check to enforce this.1156template <class Derived, class Base>1157Derived* CheckedDowncastToActualType(Base* base) {1158static_assert(std::is_base_of<Base, Derived>::value,1159"target type not derived from source type");1160#if GTEST_HAS_RTTI1161GTEST_CHECK_(base == nullptr || dynamic_cast<Derived*>(base) != nullptr);1162#endif1163return static_cast<Derived*>(base);1164}11651166#if GTEST_HAS_STREAM_REDIRECTION11671168// Defines the stderr capturer:1169// CaptureStdout - starts capturing stdout.1170// GetCapturedStdout - stops capturing stdout and returns the captured string.1171// CaptureStderr - starts capturing stderr.1172// GetCapturedStderr - stops capturing stderr and returns the captured string.1173//1174GTEST_API_ void CaptureStdout();1175GTEST_API_ std::string GetCapturedStdout();1176GTEST_API_ void CaptureStderr();1177GTEST_API_ std::string GetCapturedStderr();11781179#endif // GTEST_HAS_STREAM_REDIRECTION1180// Returns the size (in bytes) of a file.1181GTEST_API_ size_t GetFileSize(FILE* file);11821183// Reads the entire content of a file as a string.1184GTEST_API_ std::string ReadEntireFile(FILE* file);11851186// All command line arguments.1187GTEST_API_ std::vector<std::string> GetArgvs();11881189#ifdef GTEST_HAS_DEATH_TEST11901191std::vector<std::string> GetInjectableArgvs();1192// Deprecated: pass the args vector by value instead.1193void SetInjectableArgvs(const std::vector<std::string>* new_argvs);1194void SetInjectableArgvs(const std::vector<std::string>& new_argvs);1195void ClearInjectableArgvs();11961197#endif // GTEST_HAS_DEATH_TEST11981199// Defines synchronization primitives.1200#ifdef GTEST_IS_THREADSAFE12011202#ifdef GTEST_OS_WINDOWS1203// Provides leak-safe Windows kernel handle ownership.1204// Used in death tests and in threading support.1205class GTEST_API_ AutoHandle {1206public:1207// Assume that Win32 HANDLE type is equivalent to void*. Doing so allows us to1208// avoid including <windows.h> in this header file. Including <windows.h> is1209// undesirable because it defines a lot of symbols and macros that tend to1210// conflict with client code. This assumption is verified by1211// WindowsTypesTest.HANDLEIsVoidStar.1212typedef void* Handle;1213AutoHandle();1214explicit AutoHandle(Handle handle);12151216~AutoHandle();12171218Handle Get() const;1219void Reset();1220void Reset(Handle handle);12211222private:1223// Returns true if and only if the handle is a valid handle object that can be1224// closed.1225bool IsCloseable() const;12261227Handle handle_;12281229AutoHandle(const AutoHandle&) = delete;1230AutoHandle& operator=(const AutoHandle&) = delete;1231};1232#endif12331234#if GTEST_HAS_NOTIFICATION_1235// Notification has already been imported into the namespace.1236// Nothing to do here.12371238#else1239GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \1240/* class A needs to have dll-interface to be used by clients of class B */)12411242// Allows a controller thread to pause execution of newly created1243// threads until notified. Instances of this class must be created1244// and destroyed in the controller thread.1245//1246// This class is only for testing Google Test's own constructs. Do not1247// use it in user tests, either directly or indirectly.1248// TODO(b/203539622): Replace unconditionally with absl::Notification.1249class GTEST_API_ Notification {1250public:1251Notification() : notified_(false) {}1252Notification(const Notification&) = delete;1253Notification& operator=(const Notification&) = delete;12541255// Notifies all threads created with this notification to start. Must1256// be called from the controller thread.1257void Notify() {1258std::lock_guard<std::mutex> lock(mu_);1259notified_ = true;1260cv_.notify_all();1261}12621263// Blocks until the controller thread notifies. Must be called from a test1264// thread.1265void WaitForNotification() {1266std::unique_lock<std::mutex> lock(mu_);1267cv_.wait(lock, [this]() { return notified_; });1268}12691270private:1271std::mutex mu_;1272std::condition_variable cv_;1273bool notified_;1274};1275GTEST_DISABLE_MSC_WARNINGS_POP_() // 42511276#endif // GTEST_HAS_NOTIFICATION_12771278// On MinGW, we can have both GTEST_OS_WINDOWS and GTEST_HAS_PTHREAD1279// defined, but we don't want to use MinGW's pthreads implementation, which1280// has conformance problems with some versions of the POSIX standard.1281#if GTEST_HAS_PTHREAD && !defined(GTEST_OS_WINDOWS_MINGW)12821283// As a C-function, ThreadFuncWithCLinkage cannot be templated itself.1284// Consequently, it cannot select a correct instantiation of ThreadWithParam1285// in order to call its Run(). Introducing ThreadWithParamBase as a1286// non-templated base class for ThreadWithParam allows us to bypass this1287// problem.1288class ThreadWithParamBase {1289public:1290virtual ~ThreadWithParamBase() = default;1291virtual void Run() = 0;1292};12931294// pthread_create() accepts a pointer to a function type with the C linkage.1295// According to the Standard (7.5/1), function types with different linkages1296// are different even if they are otherwise identical. Some compilers (for1297// example, SunStudio) treat them as different types. Since class methods1298// cannot be defined with C-linkage we need to define a free C-function to1299// pass into pthread_create().1300extern "C" inline void* ThreadFuncWithCLinkage(void* thread) {1301static_cast<ThreadWithParamBase*>(thread)->Run();1302return nullptr;1303}13041305// Helper class for testing Google Test's multi-threading constructs.1306// To use it, write:1307//1308// void ThreadFunc(int param) { /* Do things with param */ }1309// Notification thread_can_start;1310// ...1311// // The thread_can_start parameter is optional; you can supply NULL.1312// ThreadWithParam<int> thread(&ThreadFunc, 5, &thread_can_start);1313// thread_can_start.Notify();1314//1315// These classes are only for testing Google Test's own constructs. Do1316// not use them in user tests, either directly or indirectly.1317template <typename T>1318class ThreadWithParam : public ThreadWithParamBase {1319public:1320typedef void UserThreadFunc(T);13211322ThreadWithParam(UserThreadFunc* func, T param, Notification* thread_can_start)1323: func_(func),1324param_(param),1325thread_can_start_(thread_can_start),1326finished_(false) {1327ThreadWithParamBase* const base = this;1328// The thread can be created only after all fields except thread_1329// have been initialized.1330GTEST_CHECK_POSIX_SUCCESS_(1331pthread_create(&thread_, nullptr, &ThreadFuncWithCLinkage, base));1332}1333~ThreadWithParam() override { Join(); }13341335void Join() {1336if (!finished_) {1337GTEST_CHECK_POSIX_SUCCESS_(pthread_join(thread_, nullptr));1338finished_ = true;1339}1340}13411342void Run() override {1343if (thread_can_start_ != nullptr) thread_can_start_->WaitForNotification();1344func_(param_);1345}13461347private:1348UserThreadFunc* const func_; // User-supplied thread function.1349const T param_; // User-supplied parameter to the thread function.1350// When non-NULL, used to block execution until the controller thread1351// notifies.1352Notification* const thread_can_start_;1353bool finished_; // true if and only if we know that the thread function has1354// finished.1355pthread_t thread_; // The native thread object.13561357ThreadWithParam(const ThreadWithParam&) = delete;1358ThreadWithParam& operator=(const ThreadWithParam&) = delete;1359};1360#endif // !GTEST_OS_WINDOWS && GTEST_HAS_PTHREAD ||1361// GTEST_HAS_MUTEX_AND_THREAD_LOCAL_13621363#if GTEST_HAS_MUTEX_AND_THREAD_LOCAL_1364// Mutex and ThreadLocal have already been imported into the namespace.1365// Nothing to do here.13661367#elif defined(GTEST_OS_WINDOWS) && !defined(GTEST_OS_WINDOWS_PHONE) && \1368!defined(GTEST_OS_WINDOWS_RT)13691370// Mutex implements mutex on Windows platforms. It is used in conjunction1371// with class MutexLock:1372//1373// Mutex mutex;1374// ...1375// MutexLock lock(&mutex); // Acquires the mutex and releases it at the1376// // end of the current scope.1377//1378// A static Mutex *must* be defined or declared using one of the following1379// macros:1380// GTEST_DEFINE_STATIC_MUTEX_(g_some_mutex);1381// GTEST_DECLARE_STATIC_MUTEX_(g_some_mutex);1382//1383// (A non-static Mutex is defined/declared in the usual way).1384class GTEST_API_ Mutex {1385public:1386enum MutexType { kStatic = 0, kDynamic = 1 };1387// We rely on kStaticMutex being 0 as it is to what the linker initializes1388// type_ in static mutexes. critical_section_ will be initialized lazily1389// in ThreadSafeLazyInit().1390enum StaticConstructorSelector { kStaticMutex = 0 };13911392// This constructor intentionally does nothing. It relies on type_ being1393// statically initialized to 0 (effectively setting it to kStatic) and on1394// ThreadSafeLazyInit() to lazily initialize the rest of the members.1395explicit Mutex(StaticConstructorSelector /*dummy*/) {}13961397Mutex();1398~Mutex();13991400void Lock();14011402void Unlock();14031404// Does nothing if the current thread holds the mutex. Otherwise, crashes1405// with high probability.1406void AssertHeld();14071408private:1409// Initializes owner_thread_id_ and critical_section_ in static mutexes.1410void ThreadSafeLazyInit();14111412// Per https://blogs.msdn.microsoft.com/oldnewthing/20040223-00/?p=40503,1413// we assume that 0 is an invalid value for thread IDs.1414unsigned int owner_thread_id_;14151416// For static mutexes, we rely on these members being initialized to zeros1417// by the linker.1418MutexType type_;1419long critical_section_init_phase_; // NOLINT1420GTEST_CRITICAL_SECTION* critical_section_;14211422Mutex(const Mutex&) = delete;1423Mutex& operator=(const Mutex&) = delete;1424};14251426#define GTEST_DECLARE_STATIC_MUTEX_(mutex) \1427extern ::testing::internal::Mutex mutex14281429#define GTEST_DEFINE_STATIC_MUTEX_(mutex) \1430::testing::internal::Mutex mutex(::testing::internal::Mutex::kStaticMutex)14311432// We cannot name this class MutexLock because the ctor declaration would1433// conflict with a macro named MutexLock, which is defined on some1434// platforms. That macro is used as a defensive measure to prevent against1435// inadvertent misuses of MutexLock like "MutexLock(&mu)" rather than1436// "MutexLock l(&mu)". Hence the typedef trick below.1437class GTestMutexLock {1438public:1439explicit GTestMutexLock(Mutex* mutex) : mutex_(mutex) { mutex_->Lock(); }14401441~GTestMutexLock() { mutex_->Unlock(); }14421443private:1444Mutex* const mutex_;14451446GTestMutexLock(const GTestMutexLock&) = delete;1447GTestMutexLock& operator=(const GTestMutexLock&) = delete;1448};14491450typedef GTestMutexLock MutexLock;14511452// Base class for ValueHolder<T>. Allows a caller to hold and delete a value1453// without knowing its type.1454class ThreadLocalValueHolderBase {1455public:1456virtual ~ThreadLocalValueHolderBase() {}1457};14581459// Provides a way for a thread to send notifications to a ThreadLocal1460// regardless of its parameter type.1461class ThreadLocalBase {1462public:1463// Creates a new ValueHolder<T> object holding a default value passed to1464// this ThreadLocal<T>'s constructor and returns it. It is the caller's1465// responsibility not to call this when the ThreadLocal<T> instance already1466// has a value on the current thread.1467virtual ThreadLocalValueHolderBase* NewValueForCurrentThread() const = 0;14681469protected:1470ThreadLocalBase() {}1471virtual ~ThreadLocalBase() {}14721473private:1474ThreadLocalBase(const ThreadLocalBase&) = delete;1475ThreadLocalBase& operator=(const ThreadLocalBase&) = delete;1476};14771478// Maps a thread to a set of ThreadLocals that have values instantiated on that1479// thread and notifies them when the thread exits. A ThreadLocal instance is1480// expected to persist until all threads it has values on have terminated.1481class GTEST_API_ ThreadLocalRegistry {1482public:1483// Registers thread_local_instance as having value on the current thread.1484// Returns a value that can be used to identify the thread from other threads.1485static ThreadLocalValueHolderBase* GetValueOnCurrentThread(1486const ThreadLocalBase* thread_local_instance);14871488// Invoked when a ThreadLocal instance is destroyed.1489static void OnThreadLocalDestroyed(1490const ThreadLocalBase* thread_local_instance);1491};14921493class GTEST_API_ ThreadWithParamBase {1494public:1495void Join();14961497protected:1498class Runnable {1499public:1500virtual ~Runnable() {}1501virtual void Run() = 0;1502};15031504ThreadWithParamBase(Runnable* runnable, Notification* thread_can_start);1505virtual ~ThreadWithParamBase();15061507private:1508AutoHandle thread_;1509};15101511// Helper class for testing Google Test's multi-threading constructs.1512template <typename T>1513class ThreadWithParam : public ThreadWithParamBase {1514public:1515typedef void UserThreadFunc(T);15161517ThreadWithParam(UserThreadFunc* func, T param, Notification* thread_can_start)1518: ThreadWithParamBase(new RunnableImpl(func, param), thread_can_start) {}1519virtual ~ThreadWithParam() {}15201521private:1522class RunnableImpl : public Runnable {1523public:1524RunnableImpl(UserThreadFunc* func, T param) : func_(func), param_(param) {}1525virtual ~RunnableImpl() {}1526virtual void Run() { func_(param_); }15271528private:1529UserThreadFunc* const func_;1530const T param_;15311532RunnableImpl(const RunnableImpl&) = delete;1533RunnableImpl& operator=(const RunnableImpl&) = delete;1534};15351536ThreadWithParam(const ThreadWithParam&) = delete;1537ThreadWithParam& operator=(const ThreadWithParam&) = delete;1538};15391540// Implements thread-local storage on Windows systems.1541//1542// // Thread 11543// ThreadLocal<int> tl(100); // 100 is the default value for each thread.1544//1545// // Thread 21546// tl.set(150); // Changes the value for thread 2 only.1547// EXPECT_EQ(150, tl.get());1548//1549// // Thread 11550// EXPECT_EQ(100, tl.get()); // In thread 1, tl has the original value.1551// tl.set(200);1552// EXPECT_EQ(200, tl.get());1553//1554// The template type argument T must have a public copy constructor.1555// In addition, the default ThreadLocal constructor requires T to have1556// a public default constructor.1557//1558// The users of a TheadLocal instance have to make sure that all but one1559// threads (including the main one) using that instance have exited before1560// destroying it. Otherwise, the per-thread objects managed for them by the1561// ThreadLocal instance are not guaranteed to be destroyed on all platforms.1562//1563// Google Test only uses global ThreadLocal objects. That means they1564// will die after main() has returned. Therefore, no per-thread1565// object managed by Google Test will be leaked as long as all threads1566// using Google Test have exited when main() returns.1567template <typename T>1568class ThreadLocal : public ThreadLocalBase {1569public:1570ThreadLocal() : default_factory_(new DefaultValueHolderFactory()) {}1571explicit ThreadLocal(const T& value)1572: default_factory_(new InstanceValueHolderFactory(value)) {}15731574~ThreadLocal() override { ThreadLocalRegistry::OnThreadLocalDestroyed(this); }15751576T* pointer() { return GetOrCreateValue(); }1577const T* pointer() const { return GetOrCreateValue(); }1578const T& get() const { return *pointer(); }1579void set(const T& value) { *pointer() = value; }15801581private:1582// Holds a value of T. Can be deleted via its base class without the caller1583// knowing the type of T.1584class ValueHolder : public ThreadLocalValueHolderBase {1585public:1586ValueHolder() : value_() {}1587explicit ValueHolder(const T& value) : value_(value) {}15881589T* pointer() { return &value_; }15901591private:1592T value_;1593ValueHolder(const ValueHolder&) = delete;1594ValueHolder& operator=(const ValueHolder&) = delete;1595};15961597T* GetOrCreateValue() const {1598return static_cast<ValueHolder*>(1599ThreadLocalRegistry::GetValueOnCurrentThread(this))1600->pointer();1601}16021603ThreadLocalValueHolderBase* NewValueForCurrentThread() const override {1604return default_factory_->MakeNewHolder();1605}16061607class ValueHolderFactory {1608public:1609ValueHolderFactory() {}1610virtual ~ValueHolderFactory() {}1611virtual ValueHolder* MakeNewHolder() const = 0;16121613private:1614ValueHolderFactory(const ValueHolderFactory&) = delete;1615ValueHolderFactory& operator=(const ValueHolderFactory&) = delete;1616};16171618class DefaultValueHolderFactory : public ValueHolderFactory {1619public:1620DefaultValueHolderFactory() {}1621ValueHolder* MakeNewHolder() const override { return new ValueHolder(); }16221623private:1624DefaultValueHolderFactory(const DefaultValueHolderFactory&) = delete;1625DefaultValueHolderFactory& operator=(const DefaultValueHolderFactory&) =1626delete;1627};16281629class InstanceValueHolderFactory : public ValueHolderFactory {1630public:1631explicit InstanceValueHolderFactory(const T& value) : value_(value) {}1632ValueHolder* MakeNewHolder() const override {1633return new ValueHolder(value_);1634}16351636private:1637const T value_; // The value for each thread.16381639InstanceValueHolderFactory(const InstanceValueHolderFactory&) = delete;1640InstanceValueHolderFactory& operator=(const InstanceValueHolderFactory&) =1641delete;1642};16431644std::unique_ptr<ValueHolderFactory> default_factory_;16451646ThreadLocal(const ThreadLocal&) = delete;1647ThreadLocal& operator=(const ThreadLocal&) = delete;1648};16491650#elif GTEST_HAS_PTHREAD16511652// MutexBase and Mutex implement mutex on pthreads-based platforms.1653class MutexBase {1654public:1655// Acquires this mutex.1656void Lock() {1657GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_lock(&mutex_));1658owner_ = pthread_self();1659has_owner_ = true;1660}16611662// Releases this mutex.1663void Unlock() {1664// Since the lock is being released the owner_ field should no longer be1665// considered valid. We don't protect writing to has_owner_ here, as it's1666// the caller's responsibility to ensure that the current thread holds the1667// mutex when this is called.1668has_owner_ = false;1669GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_unlock(&mutex_));1670}16711672// Does nothing if the current thread holds the mutex. Otherwise, crashes1673// with high probability.1674void AssertHeld() const {1675GTEST_CHECK_(has_owner_ && pthread_equal(owner_, pthread_self()))1676<< "The current thread is not holding the mutex @" << this;1677}16781679// A static mutex may be used before main() is entered. It may even1680// be used before the dynamic initialization stage. Therefore we1681// must be able to initialize a static mutex object at link time.1682// This means MutexBase has to be a POD and its member variables1683// have to be public.1684public:1685pthread_mutex_t mutex_; // The underlying pthread mutex.1686// has_owner_ indicates whether the owner_ field below contains a valid thread1687// ID and is therefore safe to inspect (e.g., to use in pthread_equal()). All1688// accesses to the owner_ field should be protected by a check of this field.1689// An alternative might be to memset() owner_ to all zeros, but there's no1690// guarantee that a zero'd pthread_t is necessarily invalid or even different1691// from pthread_self().1692bool has_owner_;1693pthread_t owner_; // The thread holding the mutex.1694};16951696// Forward-declares a static mutex.1697#define GTEST_DECLARE_STATIC_MUTEX_(mutex) \1698extern ::testing::internal::MutexBase mutex16991700// Defines and statically (i.e. at link time) initializes a static mutex.1701// The initialization list here does not explicitly initialize each field,1702// instead relying on default initialization for the unspecified fields. In1703// particular, the owner_ field (a pthread_t) is not explicitly initialized.1704// This allows initialization to work whether pthread_t is a scalar or struct.1705// The flag -Wmissing-field-initializers must not be specified for this to work.1706#define GTEST_DEFINE_STATIC_MUTEX_(mutex) \1707::testing::internal::MutexBase mutex = {PTHREAD_MUTEX_INITIALIZER, false, 0}17081709// The Mutex class can only be used for mutexes created at runtime. It1710// shares its API with MutexBase otherwise.1711class Mutex : public MutexBase {1712public:1713Mutex() {1714GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_init(&mutex_, nullptr));1715has_owner_ = false;1716}1717~Mutex() { GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_destroy(&mutex_)); }17181719private:1720Mutex(const Mutex&) = delete;1721Mutex& operator=(const Mutex&) = delete;1722};17231724// We cannot name this class MutexLock because the ctor declaration would1725// conflict with a macro named MutexLock, which is defined on some1726// platforms. That macro is used as a defensive measure to prevent against1727// inadvertent misuses of MutexLock like "MutexLock(&mu)" rather than1728// "MutexLock l(&mu)". Hence the typedef trick below.1729class GTestMutexLock {1730public:1731explicit GTestMutexLock(MutexBase* mutex) : mutex_(mutex) { mutex_->Lock(); }17321733~GTestMutexLock() { mutex_->Unlock(); }17341735private:1736MutexBase* const mutex_;17371738GTestMutexLock(const GTestMutexLock&) = delete;1739GTestMutexLock& operator=(const GTestMutexLock&) = delete;1740};17411742typedef GTestMutexLock MutexLock;17431744// Helpers for ThreadLocal.17451746// pthread_key_create() requires DeleteThreadLocalValue() to have1747// C-linkage. Therefore it cannot be templatized to access1748// ThreadLocal<T>. Hence the need for class1749// ThreadLocalValueHolderBase.1750class GTEST_API_ ThreadLocalValueHolderBase {1751public:1752virtual ~ThreadLocalValueHolderBase() = default;1753};17541755// Called by pthread to delete thread-local data stored by1756// pthread_setspecific().1757extern "C" inline void DeleteThreadLocalValue(void* value_holder) {1758delete static_cast<ThreadLocalValueHolderBase*>(value_holder);1759}17601761// Implements thread-local storage on pthreads-based systems.1762template <typename T>1763class GTEST_API_ ThreadLocal {1764public:1765ThreadLocal()1766: key_(CreateKey()), default_factory_(new DefaultValueHolderFactory()) {}1767explicit ThreadLocal(const T& value)1768: key_(CreateKey()),1769default_factory_(new InstanceValueHolderFactory(value)) {}17701771~ThreadLocal() {1772// Destroys the managed object for the current thread, if any.1773DeleteThreadLocalValue(pthread_getspecific(key_));17741775// Releases resources associated with the key. This will *not*1776// delete managed objects for other threads.1777GTEST_CHECK_POSIX_SUCCESS_(pthread_key_delete(key_));1778}17791780T* pointer() { return GetOrCreateValue(); }1781const T* pointer() const { return GetOrCreateValue(); }1782const T& get() const { return *pointer(); }1783void set(const T& value) { *pointer() = value; }17841785private:1786// Holds a value of type T.1787class ValueHolder : public ThreadLocalValueHolderBase {1788public:1789ValueHolder() : value_() {}1790explicit ValueHolder(const T& value) : value_(value) {}17911792T* pointer() { return &value_; }17931794private:1795T value_;1796ValueHolder(const ValueHolder&) = delete;1797ValueHolder& operator=(const ValueHolder&) = delete;1798};17991800static pthread_key_t CreateKey() {1801pthread_key_t key;1802// When a thread exits, DeleteThreadLocalValue() will be called on1803// the object managed for that thread.1804GTEST_CHECK_POSIX_SUCCESS_(1805pthread_key_create(&key, &DeleteThreadLocalValue));1806return key;1807}18081809T* GetOrCreateValue() const {1810ThreadLocalValueHolderBase* const holder =1811static_cast<ThreadLocalValueHolderBase*>(pthread_getspecific(key_));1812if (holder != nullptr) {1813return CheckedDowncastToActualType<ValueHolder>(holder)->pointer();1814}18151816ValueHolder* const new_holder = default_factory_->MakeNewHolder();1817ThreadLocalValueHolderBase* const holder_base = new_holder;1818GTEST_CHECK_POSIX_SUCCESS_(pthread_setspecific(key_, holder_base));1819return new_holder->pointer();1820}18211822class ValueHolderFactory {1823public:1824ValueHolderFactory() = default;1825virtual ~ValueHolderFactory() = default;1826virtual ValueHolder* MakeNewHolder() const = 0;18271828private:1829ValueHolderFactory(const ValueHolderFactory&) = delete;1830ValueHolderFactory& operator=(const ValueHolderFactory&) = delete;1831};18321833class DefaultValueHolderFactory : public ValueHolderFactory {1834public:1835DefaultValueHolderFactory() = default;1836ValueHolder* MakeNewHolder() const override { return new ValueHolder(); }18371838private:1839DefaultValueHolderFactory(const DefaultValueHolderFactory&) = delete;1840DefaultValueHolderFactory& operator=(const DefaultValueHolderFactory&) =1841delete;1842};18431844class InstanceValueHolderFactory : public ValueHolderFactory {1845public:1846explicit InstanceValueHolderFactory(const T& value) : value_(value) {}1847ValueHolder* MakeNewHolder() const override {1848return new ValueHolder(value_);1849}18501851private:1852const T value_; // The value for each thread.18531854InstanceValueHolderFactory(const InstanceValueHolderFactory&) = delete;1855InstanceValueHolderFactory& operator=(const InstanceValueHolderFactory&) =1856delete;1857};18581859// A key pthreads uses for looking up per-thread values.1860const pthread_key_t key_;1861std::unique_ptr<ValueHolderFactory> default_factory_;18621863ThreadLocal(const ThreadLocal&) = delete;1864ThreadLocal& operator=(const ThreadLocal&) = delete;1865};18661867#endif // GTEST_HAS_MUTEX_AND_THREAD_LOCAL_18681869#else // GTEST_IS_THREADSAFE18701871// A dummy implementation of synchronization primitives (mutex, lock,1872// and thread-local variable). Necessary for compiling Google Test where1873// mutex is not supported - using Google Test in multiple threads is not1874// supported on such platforms.18751876class Mutex {1877public:1878Mutex() {}1879void Lock() {}1880void Unlock() {}1881void AssertHeld() const {}1882};18831884#define GTEST_DECLARE_STATIC_MUTEX_(mutex) \1885extern ::testing::internal::Mutex mutex18861887#define GTEST_DEFINE_STATIC_MUTEX_(mutex) ::testing::internal::Mutex mutex18881889// We cannot name this class MutexLock because the ctor declaration would1890// conflict with a macro named MutexLock, which is defined on some1891// platforms. That macro is used as a defensive measure to prevent against1892// inadvertent misuses of MutexLock like "MutexLock(&mu)" rather than1893// "MutexLock l(&mu)". Hence the typedef trick below.1894class GTestMutexLock {1895public:1896explicit GTestMutexLock(Mutex*) {} // NOLINT1897};18981899typedef GTestMutexLock MutexLock;19001901template <typename T>1902class GTEST_API_ ThreadLocal {1903public:1904ThreadLocal() : value_() {}1905explicit ThreadLocal(const T& value) : value_(value) {}1906T* pointer() { return &value_; }1907const T* pointer() const { return &value_; }1908const T& get() const { return value_; }1909void set(const T& value) { value_ = value; }19101911private:1912T value_;1913};19141915#endif // GTEST_IS_THREADSAFE19161917// Returns the number of threads running in the process, or 0 to indicate that1918// we cannot detect it.1919GTEST_API_ size_t GetThreadCount();19201921#ifdef GTEST_OS_WINDOWS1922#define GTEST_PATH_SEP_ "\\"1923#define GTEST_HAS_ALT_PATH_SEP_ 11924#else1925#define GTEST_PATH_SEP_ "/"1926#define GTEST_HAS_ALT_PATH_SEP_ 01927#endif // GTEST_OS_WINDOWS19281929// Utilities for char.19301931// isspace(int ch) and friends accept an unsigned char or EOF. char1932// may be signed, depending on the compiler (or compiler flags).1933// Therefore we need to cast a char to unsigned char before calling1934// isspace(), etc.19351936inline bool IsAlpha(char ch) {1937return isalpha(static_cast<unsigned char>(ch)) != 0;1938}1939inline bool IsAlNum(char ch) {1940return isalnum(static_cast<unsigned char>(ch)) != 0;1941}1942inline bool IsDigit(char ch) {1943return isdigit(static_cast<unsigned char>(ch)) != 0;1944}1945inline bool IsLower(char ch) {1946return islower(static_cast<unsigned char>(ch)) != 0;1947}1948inline bool IsSpace(char ch) {1949return isspace(static_cast<unsigned char>(ch)) != 0;1950}1951inline bool IsUpper(char ch) {1952return isupper(static_cast<unsigned char>(ch)) != 0;1953}1954inline bool IsXDigit(char ch) {1955return isxdigit(static_cast<unsigned char>(ch)) != 0;1956}1957#ifdef __cpp_lib_char8_t1958inline bool IsXDigit(char8_t ch) {1959return isxdigit(static_cast<unsigned char>(ch)) != 0;1960}1961#endif1962inline bool IsXDigit(char16_t ch) {1963const unsigned char low_byte = static_cast<unsigned char>(ch);1964return ch == low_byte && isxdigit(low_byte) != 0;1965}1966inline bool IsXDigit(char32_t ch) {1967const unsigned char low_byte = static_cast<unsigned char>(ch);1968return ch == low_byte && isxdigit(low_byte) != 0;1969}1970inline bool IsXDigit(wchar_t ch) {1971const unsigned char low_byte = static_cast<unsigned char>(ch);1972return ch == low_byte && isxdigit(low_byte) != 0;1973}19741975inline char ToLower(char ch) {1976return static_cast<char>(tolower(static_cast<unsigned char>(ch)));1977}1978inline char ToUpper(char ch) {1979return static_cast<char>(toupper(static_cast<unsigned char>(ch)));1980}19811982inline std::string StripTrailingSpaces(std::string str) {1983std::string::iterator it = str.end();1984while (it != str.begin() && IsSpace(*--it)) it = str.erase(it);1985return str;1986}19871988// The testing::internal::posix namespace holds wrappers for common1989// POSIX functions. These wrappers hide the differences between1990// Windows/MSVC and POSIX systems. Since some compilers define these1991// standard functions as macros, the wrapper cannot have the same name1992// as the wrapped function.19931994namespace posix {19951996// File system porting.1997// Note: Not every I/O-related function is related to file systems, so don't1998// just disable all of them here. For example, fileno() and isatty(), etc. must1999// always be available in order to detect if a pipe points to a terminal.2000#ifdef GTEST_OS_WINDOWS20012002typedef struct _stat StatStruct;20032004#ifdef GTEST_OS_WINDOWS_MOBILE2005inline int FileNo(FILE* file) { return reinterpret_cast<int>(_fileno(file)); }2006// Stat(), RmDir(), and IsDir() are not needed on Windows CE at this2007// time and thus not defined there.2008#else2009inline int FileNo(FILE* file) { return _fileno(file); }2010#if GTEST_HAS_FILE_SYSTEM2011inline int Stat(const char* path, StatStruct* buf) { return _stat(path, buf); }2012inline int RmDir(const char* dir) { return _rmdir(dir); }2013inline bool IsDir(const StatStruct& st) { return (_S_IFDIR & st.st_mode) != 0; }2014#endif2015#endif // GTEST_OS_WINDOWS_MOBILE20162017#elif defined(GTEST_OS_ESP8266)2018typedef struct stat StatStruct;20192020inline int FileNo(FILE* file) { return fileno(file); }2021#if GTEST_HAS_FILE_SYSTEM2022inline int Stat(const char* path, StatStruct* buf) {2023// stat function not implemented on ESP82662024return 0;2025}2026inline int RmDir(const char* dir) { return rmdir(dir); }2027inline bool IsDir(const StatStruct& st) { return S_ISDIR(st.st_mode); }2028#endif20292030#else20312032typedef struct stat StatStruct;20332034inline int FileNo(FILE* file) { return fileno(file); }2035#if GTEST_HAS_FILE_SYSTEM2036inline int Stat(const char* path, StatStruct* buf) { return stat(path, buf); }2037#ifdef GTEST_OS_QURT2038// QuRT doesn't support any directory functions, including rmdir2039inline int RmDir(const char*) { return 0; }2040#else2041inline int RmDir(const char* dir) { return rmdir(dir); }2042#endif2043inline bool IsDir(const StatStruct& st) { return S_ISDIR(st.st_mode); }2044#endif20452046#endif // GTEST_OS_WINDOWS20472048// Other functions with a different name on Windows.20492050#ifdef GTEST_OS_WINDOWS20512052#ifdef __BORLANDC__2053inline int DoIsATTY(int fd) { return isatty(fd); }2054inline int StrCaseCmp(const char* s1, const char* s2) {2055return stricmp(s1, s2);2056}2057#else // !__BORLANDC__2058#if defined(GTEST_OS_WINDOWS_MOBILE) || defined(GTEST_OS_ZOS) || \2059defined(GTEST_OS_IOS) || defined(GTEST_OS_WINDOWS_PHONE) || \2060defined(GTEST_OS_WINDOWS_RT) || defined(ESP_PLATFORM)2061inline int DoIsATTY(int /* fd */) { return 0; }2062#else2063inline int DoIsATTY(int fd) { return _isatty(fd); }2064#endif // GTEST_OS_WINDOWS_MOBILE2065inline int StrCaseCmp(const char* s1, const char* s2) {2066return _stricmp(s1, s2);2067}2068#endif // __BORLANDC__20692070#else20712072inline int DoIsATTY(int fd) { return isatty(fd); }2073inline int StrCaseCmp(const char* s1, const char* s2) {2074return strcasecmp(s1, s2);2075}20762077#endif // GTEST_OS_WINDOWS20782079inline int IsATTY(int fd) {2080// DoIsATTY might change errno (for example ENOTTY in case you redirect stdout2081// to a file on Linux), which is unexpected, so save the previous value, and2082// restore it after the call.2083int savedErrno = errno;2084int isAttyValue = DoIsATTY(fd);2085errno = savedErrno;20862087return isAttyValue;2088}20892090// Functions deprecated by MSVC 8.0.20912092GTEST_DISABLE_MSC_DEPRECATED_PUSH_()20932094// ChDir(), FReopen(), FDOpen(), Read(), Write(), Close(), and2095// StrError() aren't needed on Windows CE at this time and thus not2096// defined there.2097#if GTEST_HAS_FILE_SYSTEM2098#if !defined(GTEST_OS_WINDOWS_MOBILE) && !defined(GTEST_OS_WINDOWS_PHONE) && \2099!defined(GTEST_OS_WINDOWS_RT) && !defined(GTEST_OS_WINDOWS_GAMES) && \2100!defined(GTEST_OS_ESP8266) && !defined(GTEST_OS_XTENSA) && \2101!defined(GTEST_OS_QURT)2102inline int ChDir(const char* dir) { return chdir(dir); }2103#endif2104inline FILE* FOpen(const char* path, const char* mode) {2105#if defined(GTEST_OS_WINDOWS) && !defined(GTEST_OS_WINDOWS_MINGW)2106struct wchar_codecvt : public std::codecvt<wchar_t, char, std::mbstate_t> {};2107std::wstring_convert<wchar_codecvt> converter;2108std::wstring wide_path = converter.from_bytes(path);2109std::wstring wide_mode = converter.from_bytes(mode);2110return _wfopen(wide_path.c_str(), wide_mode.c_str());2111#else // GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MINGW2112return fopen(path, mode);2113#endif // GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MINGW2114}2115#if !defined(GTEST_OS_WINDOWS_MOBILE) && !defined(GTEST_OS_QURT)2116inline FILE* FReopen(const char* path, const char* mode, FILE* stream) {2117return freopen(path, mode, stream);2118}2119inline FILE* FDOpen(int fd, const char* mode) { return fdopen(fd, mode); }2120#endif // !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_QURT2121inline int FClose(FILE* fp) { return fclose(fp); }2122#if !defined(GTEST_OS_WINDOWS_MOBILE) && !defined(GTEST_OS_QURT)2123inline int Read(int fd, void* buf, unsigned int count) {2124return static_cast<int>(read(fd, buf, count));2125}2126inline int Write(int fd, const void* buf, unsigned int count) {2127return static_cast<int>(write(fd, buf, count));2128}2129inline int Close(int fd) { return close(fd); }2130#endif // !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_QURT2131#endif // GTEST_HAS_FILE_SYSTEM21322133#if !defined(GTEST_OS_WINDOWS_MOBILE) && !defined(GTEST_OS_QURT)2134inline const char* StrError(int errnum) { return strerror(errnum); }2135#endif // !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_QURT21362137inline const char* GetEnv(const char* name) {2138#if defined(GTEST_OS_WINDOWS_MOBILE) || defined(GTEST_OS_WINDOWS_PHONE) || \2139defined(GTEST_OS_ESP8266) || defined(GTEST_OS_XTENSA) || \2140defined(GTEST_OS_QURT)2141// We are on an embedded platform, which has no environment variables.2142static_cast<void>(name); // To prevent 'unused argument' warning.2143return nullptr;2144#elif defined(__BORLANDC__) || defined(__SunOS_5_8) || defined(__SunOS_5_9)2145// Environment variables which we programmatically clear will be set to the2146// empty string rather than unset (NULL). Handle that case.2147const char* const env = getenv(name);2148return (env != nullptr && env[0] != '\0') ? env : nullptr;2149#else2150return getenv(name);2151#endif2152}21532154GTEST_DISABLE_MSC_DEPRECATED_POP_()21552156#ifdef GTEST_OS_WINDOWS_MOBILE2157// Windows CE has no C library. The abort() function is used in2158// several places in Google Test. This implementation provides a reasonable2159// imitation of standard behaviour.2160[[noreturn]] void Abort();2161#else2162[[noreturn]] inline void Abort() { abort(); }2163#endif // GTEST_OS_WINDOWS_MOBILE21642165} // namespace posix21662167// MSVC "deprecates" snprintf and issues warnings wherever it is used. In2168// order to avoid these warnings, we need to use _snprintf or _snprintf_s on2169// MSVC-based platforms. We map the GTEST_SNPRINTF_ macro to the appropriate2170// function in order to achieve that. We use macro definition here because2171// snprintf is a variadic function.2172#if defined(_MSC_VER) && !defined(GTEST_OS_WINDOWS_MOBILE)2173// MSVC 2005 and above support variadic macros.2174#define GTEST_SNPRINTF_(buffer, size, format, ...) \2175_snprintf_s(buffer, size, size, format, __VA_ARGS__)2176#elif defined(_MSC_VER)2177// Windows CE does not define _snprintf_s2178#define GTEST_SNPRINTF_ _snprintf2179#else2180#define GTEST_SNPRINTF_ snprintf2181#endif21822183// The biggest signed integer type the compiler supports.2184//2185// long long is guaranteed to be at least 64-bits in C++11.2186using BiggestInt = long long; // NOLINT21872188// The maximum number a BiggestInt can represent.2189constexpr BiggestInt kMaxBiggestInt = (std::numeric_limits<BiggestInt>::max)();21902191// This template class serves as a compile-time function from size to2192// type. It maps a size in bytes to a primitive type with that2193// size. e.g.2194//2195// TypeWithSize<4>::UInt2196//2197// is typedef-ed to be unsigned int (unsigned integer made up of 42198// bytes).2199//2200// Such functionality should belong to STL, but I cannot find it2201// there.2202//2203// Google Test uses this class in the implementation of floating-point2204// comparison.2205//2206// For now it only handles UInt (unsigned int) as that's all Google Test2207// needs. Other types can be easily added in the future if need2208// arises.2209template <size_t size>2210class TypeWithSize {2211public:2212// This prevents the user from using TypeWithSize<N> with incorrect2213// values of N.2214using UInt = void;2215};22162217// The specialization for size 4.2218template <>2219class TypeWithSize<4> {2220public:2221using Int = std::int32_t;2222using UInt = std::uint32_t;2223};22242225// The specialization for size 8.2226template <>2227class TypeWithSize<8> {2228public:2229using Int = std::int64_t;2230using UInt = std::uint64_t;2231};22322233// Integer types of known sizes.2234using TimeInMillis = int64_t; // Represents time in milliseconds.22352236// Utilities for command line flags and environment variables.22372238// Macro for referencing flags.2239#if !defined(GTEST_FLAG)2240#define GTEST_FLAG_NAME_(name) gtest_##name2241#define GTEST_FLAG(name) FLAGS_gtest_##name2242#endif // !defined(GTEST_FLAG)22432244// Pick a command line flags implementation.2245#ifdef GTEST_INTERNAL_HAS_ABSL_FLAGS22462247// Macros for defining flags.2248#define GTEST_DEFINE_bool_(name, default_val, doc) \2249ABSL_FLAG(bool, GTEST_FLAG_NAME_(name), default_val, doc)2250#define GTEST_DEFINE_int32_(name, default_val, doc) \2251ABSL_FLAG(int32_t, GTEST_FLAG_NAME_(name), default_val, doc)2252#define GTEST_DEFINE_string_(name, default_val, doc) \2253ABSL_FLAG(std::string, GTEST_FLAG_NAME_(name), default_val, doc)22542255// Macros for declaring flags.2256#define GTEST_DECLARE_bool_(name) \2257ABSL_DECLARE_FLAG(bool, GTEST_FLAG_NAME_(name))2258#define GTEST_DECLARE_int32_(name) \2259ABSL_DECLARE_FLAG(int32_t, GTEST_FLAG_NAME_(name))2260#define GTEST_DECLARE_string_(name) \2261ABSL_DECLARE_FLAG(std::string, GTEST_FLAG_NAME_(name))22622263#define GTEST_FLAG_SAVER_ ::absl::FlagSaver22642265#define GTEST_FLAG_GET(name) ::absl::GetFlag(GTEST_FLAG(name))2266#define GTEST_FLAG_SET(name, value) \2267(void)(::absl::SetFlag(>EST_FLAG(name), value))2268#define GTEST_USE_OWN_FLAGFILE_FLAG_ 022692270#undef GTEST_INTERNAL_HAS_ABSL_FLAGS2271#else // ndef GTEST_INTERNAL_HAS_ABSL_FLAGS22722273// Macros for defining flags.2274#define GTEST_DEFINE_bool_(name, default_val, doc) \2275namespace testing { \2276GTEST_API_ bool GTEST_FLAG(name) = (default_val); \2277} \2278static_assert(true, "no-op to require trailing semicolon")2279#define GTEST_DEFINE_int32_(name, default_val, doc) \2280namespace testing { \2281GTEST_API_ std::int32_t GTEST_FLAG(name) = (default_val); \2282} \2283static_assert(true, "no-op to require trailing semicolon")2284#define GTEST_DEFINE_string_(name, default_val, doc) \2285namespace testing { \2286GTEST_API_ ::std::string GTEST_FLAG(name) = (default_val); \2287} \2288static_assert(true, "no-op to require trailing semicolon")22892290// Macros for declaring flags.2291#define GTEST_DECLARE_bool_(name) \2292namespace testing { \2293GTEST_API_ extern bool GTEST_FLAG(name); \2294} \2295static_assert(true, "no-op to require trailing semicolon")2296#define GTEST_DECLARE_int32_(name) \2297namespace testing { \2298GTEST_API_ extern std::int32_t GTEST_FLAG(name); \2299} \2300static_assert(true, "no-op to require trailing semicolon")2301#define GTEST_DECLARE_string_(name) \2302namespace testing { \2303GTEST_API_ extern ::std::string GTEST_FLAG(name); \2304} \2305static_assert(true, "no-op to require trailing semicolon")23062307#define GTEST_FLAG_SAVER_ ::testing::internal::GTestFlagSaver23082309#define GTEST_FLAG_GET(name) ::testing::GTEST_FLAG(name)2310#define GTEST_FLAG_SET(name, value) (void)(::testing::GTEST_FLAG(name) = value)2311#define GTEST_USE_OWN_FLAGFILE_FLAG_ 123122313#endif // GTEST_INTERNAL_HAS_ABSL_FLAGS23142315// Thread annotations2316#if !defined(GTEST_EXCLUSIVE_LOCK_REQUIRED_)2317#define GTEST_EXCLUSIVE_LOCK_REQUIRED_(locks)2318#define GTEST_LOCK_EXCLUDED_(locks)2319#endif // !defined(GTEST_EXCLUSIVE_LOCK_REQUIRED_)23202321// Parses 'str' for a 32-bit signed integer. If successful, writes the result2322// to *value and returns true; otherwise leaves *value unchanged and returns2323// false.2324GTEST_API_ bool ParseInt32(const Message& src_text, const char* str,2325int32_t* value);23262327// Parses a bool/int32_t/string from the environment variable2328// corresponding to the given Google Test flag.2329bool BoolFromGTestEnv(const char* flag, bool default_val);2330GTEST_API_ int32_t Int32FromGTestEnv(const char* flag, int32_t default_val);2331std::string OutputFlagAlsoCheckEnvVar();2332const char* StringFromGTestEnv(const char* flag, const char* default_val);23332334} // namespace internal2335} // namespace testing23362337#ifdef GTEST_HAS_ABSL2338// Always use absl::any for UniversalPrinter<> specializations if googletest2339// is built with absl support.2340#define GTEST_INTERNAL_HAS_ANY 12341#include "absl/types/any.h"2342namespace testing {2343namespace internal {2344using Any = ::absl::any;2345} // namespace internal2346} // namespace testing2347#else2348#if defined(__cpp_lib_any) || (GTEST_INTERNAL_HAS_INCLUDE(<any>) && \2349GTEST_INTERNAL_CPLUSPLUS_LANG >= 201703L && \2350(!defined(_MSC_VER) || GTEST_HAS_RTTI))2351// Otherwise for C++17 and higher use std::any for UniversalPrinter<>2352// specializations.2353#define GTEST_INTERNAL_HAS_ANY 12354#include <any>2355namespace testing {2356namespace internal {2357using Any = ::std::any;2358} // namespace internal2359} // namespace testing2360// The case where absl is configured NOT to alias std::any is not2361// supported.2362#endif // __cpp_lib_any2363#endif // GTEST_HAS_ABSL23642365#ifndef GTEST_INTERNAL_HAS_ANY2366#define GTEST_INTERNAL_HAS_ANY 02367#endif23682369#ifdef GTEST_HAS_ABSL2370// Always use absl::optional for UniversalPrinter<> specializations if2371// googletest is built with absl support.2372#define GTEST_INTERNAL_HAS_OPTIONAL 12373#include "absl/types/optional.h"2374namespace testing {2375namespace internal {2376template <typename T>2377using Optional = ::absl::optional<T>;2378inline ::absl::nullopt_t Nullopt() { return ::absl::nullopt; }2379} // namespace internal2380} // namespace testing2381#else2382#if defined(__cpp_lib_optional) || (GTEST_INTERNAL_HAS_INCLUDE(<optional>) && \2383GTEST_INTERNAL_CPLUSPLUS_LANG >= 201703L)2384// Otherwise for C++17 and higher use std::optional for UniversalPrinter<>2385// specializations.2386#define GTEST_INTERNAL_HAS_OPTIONAL 12387#include <optional>2388namespace testing {2389namespace internal {2390template <typename T>2391using Optional = ::std::optional<T>;2392inline ::std::nullopt_t Nullopt() { return ::std::nullopt; }2393} // namespace internal2394} // namespace testing2395// The case where absl is configured NOT to alias std::optional is not2396// supported.2397#endif // __cpp_lib_optional2398#endif // GTEST_HAS_ABSL23992400#ifndef GTEST_INTERNAL_HAS_OPTIONAL2401#define GTEST_INTERNAL_HAS_OPTIONAL 02402#endif24032404#if defined(__cpp_lib_span) || (GTEST_INTERNAL_HAS_INCLUDE(<span>) && \2405GTEST_INTERNAL_CPLUSPLUS_LANG >= 202002L)2406#define GTEST_INTERNAL_HAS_STD_SPAN 12407#endif // __cpp_lib_span24082409#ifndef GTEST_INTERNAL_HAS_STD_SPAN2410#define GTEST_INTERNAL_HAS_STD_SPAN 02411#endif24122413#ifdef GTEST_HAS_ABSL2414// Always use absl::string_view for Matcher<> specializations if googletest2415// is built with absl support.2416#define GTEST_INTERNAL_HAS_STRING_VIEW 12417#include "absl/strings/string_view.h"2418namespace testing {2419namespace internal {2420using StringView = ::absl::string_view;2421} // namespace internal2422} // namespace testing2423#else2424#if defined(__cpp_lib_string_view) || \2425(GTEST_INTERNAL_HAS_INCLUDE(<string_view>) && \2426GTEST_INTERNAL_CPLUSPLUS_LANG >= 201703L)2427// Otherwise for C++17 and higher use std::string_view for Matcher<>2428// specializations.2429#define GTEST_INTERNAL_HAS_STRING_VIEW 12430#include <string_view>2431namespace testing {2432namespace internal {2433using StringView = ::std::string_view;2434} // namespace internal2435} // namespace testing2436// The case where absl is configured NOT to alias std::string_view is not2437// supported.2438#endif // __cpp_lib_string_view2439#endif // GTEST_HAS_ABSL24402441#ifndef GTEST_INTERNAL_HAS_STRING_VIEW2442#define GTEST_INTERNAL_HAS_STRING_VIEW 02443#endif24442445#ifdef GTEST_HAS_ABSL2446// Always use absl::variant for UniversalPrinter<> specializations if googletest2447// is built with absl support.2448#define GTEST_INTERNAL_HAS_VARIANT 12449#include "absl/types/variant.h"2450namespace testing {2451namespace internal {2452template <typename... T>2453using Variant = ::absl::variant<T...>;2454} // namespace internal2455} // namespace testing2456#else2457#if defined(__cpp_lib_variant) || (GTEST_INTERNAL_HAS_INCLUDE(<variant>) && \2458GTEST_INTERNAL_CPLUSPLUS_LANG >= 201703L)2459// Otherwise for C++17 and higher use std::variant for UniversalPrinter<>2460// specializations.2461#define GTEST_INTERNAL_HAS_VARIANT 12462#include <variant>2463namespace testing {2464namespace internal {2465template <typename... T>2466using Variant = ::std::variant<T...>;2467} // namespace internal2468} // namespace testing2469// The case where absl is configured NOT to alias std::variant is not supported.2470#endif // __cpp_lib_variant2471#endif // GTEST_HAS_ABSL24722473#ifndef GTEST_INTERNAL_HAS_VARIANT2474#define GTEST_INTERNAL_HAS_VARIANT 02475#endif24762477#if (defined(__cpp_lib_three_way_comparison) || \2478(GTEST_INTERNAL_HAS_INCLUDE(<compare>) && \2479GTEST_INTERNAL_CPLUSPLUS_LANG >= 201907L))2480#define GTEST_INTERNAL_HAS_COMPARE_LIB 12481#else2482#define GTEST_INTERNAL_HAS_COMPARE_LIB 02483#endif24842485#endif // GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_248624872488