281
281
#error C++ versions less than C++14 are not supported.
282
282
#endif
283
283
284
+ // MSVC >= 19.11 (VS 2017 Update 3) supports __has_include.
285
+ #ifdef __has_include
286
+ #define GTEST_INTERNAL_HAS_INCLUDE __has_include
287
+ #else
288
+ #define GTEST_INTERNAL_HAS_INCLUDE (...) 0
289
+ #endif
290
+
291
+ // Detect C++ feature test macros as gracefully as possible.
292
+ // MSVC >= 19.15, Clang >= 3.4.1, and GCC >= 4.1.2 support feature test macros.
293
+ #if GTEST_INTERNAL_CPLUSPLUS_LANG >= 202002L && \
294
+ (!defined(__has_include) || GTEST_INTERNAL_HAS_INCLUDE(<version>))
295
+ #include < version> // C++20 and later
296
+ #elif (!defined(__has_include) || GTEST_INTERNAL_HAS_INCLUDE(<ciso646>))
297
+ #include < ciso646> // Pre-C++20
298
+ #endif
299
+
284
300
#include < ctype.h> // for isspace, etc
285
301
#include < stddef.h> // for ptrdiff_t
286
302
#include < stdio.h>
@@ -829,9 +845,9 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
829
845
#ifndef GTEST_API_
830
846
831
847
#ifdef _MSC_VER
832
- #if GTEST_LINKED_AS_SHARED_LIBRARY
848
+ #if defined(GTEST_LINKED_AS_SHARED_LIBRARY) && GTEST_LINKED_AS_SHARED_LIBRARY
833
849
#define GTEST_API_ __declspec (dllimport)
834
- #elif GTEST_CREATE_SHARED_LIBRARY
850
+ #elif defined(GTEST_CREATE_SHARED_LIBRARY) && GTEST_CREATE_SHARED_LIBRARY
835
851
#define GTEST_API_ __declspec (dllexport)
836
852
#endif
837
853
#elif GTEST_HAVE_ATTRIBUTE_(visibility)
@@ -2351,9 +2367,9 @@ using Any = ::absl::any;
2351
2367
} // namespace internal
2352
2368
} // namespace testing
2353
2369
#else
2354
- #ifdef __has_include
2355
- # if __has_include(<any>) && GTEST_INTERNAL_CPLUSPLUS_LANG >= 201703L && \
2356
- (!defined(_MSC_VER) || GTEST_HAS_RTTI)
2370
+ #if defined(__cpp_lib_any) || (GTEST_INTERNAL_HAS_INCLUDE(<any>) && \
2371
+ GTEST_INTERNAL_CPLUSPLUS_LANG >= 201703L && \
2372
+ (!defined(_MSC_VER) || GTEST_HAS_RTTI) )
2357
2373
// Otherwise for C++17 and higher use std::any for UniversalPrinter<>
2358
2374
// specializations.
2359
2375
#define GTEST_INTERNAL_HAS_ANY 1
@@ -2365,8 +2381,7 @@ using Any = ::std::any;
2365
2381
} // namespace testing
2366
2382
// The case where absl is configured NOT to alias std::any is not
2367
2383
// supported.
2368
- #endif // __has_include(<any>) && GTEST_INTERNAL_CPLUSPLUS_LANG >= 201703L
2369
- #endif // __has_include
2384
+ #endif // __cpp_lib_any
2370
2385
#endif // GTEST_HAS_ABSL
2371
2386
2372
2387
#ifndef GTEST_INTERNAL_HAS_ANY
@@ -2386,8 +2401,8 @@ inline ::absl::nullopt_t Nullopt() { return ::absl::nullopt; }
2386
2401
} // namespace internal
2387
2402
} // namespace testing
2388
2403
#else
2389
- #ifdef __has_include
2390
- # if __has_include(<optional>) && GTEST_INTERNAL_CPLUSPLUS_LANG >= 201703L
2404
+ #if defined(__cpp_lib_optional) || (GTEST_INTERNAL_HAS_INCLUDE(<optional>) && \
2405
+ GTEST_INTERNAL_CPLUSPLUS_LANG >= 201703L )
2391
2406
// Otherwise for C++17 and higher use std::optional for UniversalPrinter<>
2392
2407
// specializations.
2393
2408
#define GTEST_INTERNAL_HAS_OPTIONAL 1
@@ -2401,19 +2416,17 @@ inline ::std::nullopt_t Nullopt() { return ::std::nullopt; }
2401
2416
} // namespace testing
2402
2417
// The case where absl is configured NOT to alias std::optional is not
2403
2418
// supported.
2404
- #endif // __has_include(<optional>) && GTEST_INTERNAL_CPLUSPLUS_LANG >= 201703L
2405
- #endif // __has_include
2419
+ #endif // __cpp_lib_optional
2406
2420
#endif // GTEST_HAS_ABSL
2407
2421
2408
2422
#ifndef GTEST_INTERNAL_HAS_OPTIONAL
2409
2423
#define GTEST_INTERNAL_HAS_OPTIONAL 0
2410
2424
#endif
2411
2425
2412
- #ifdef __has_include
2413
- # if __has_include(<span>) && GTEST_INTERNAL_CPLUSPLUS_LANG >= 202002L
2426
+ #if defined(__cpp_lib_span) || (GTEST_INTERNAL_HAS_INCLUDE(<span>) && \
2427
+ GTEST_INTERNAL_CPLUSPLUS_LANG >= 202002L )
2414
2428
#define GTEST_INTERNAL_HAS_STD_SPAN 1
2415
- #endif // __has_include(<span>) && GTEST_INTERNAL_CPLUSPLUS_LANG >= 202002L
2416
- #endif // __has_include
2429
+ #endif // __cpp_lib_span
2417
2430
2418
2431
#ifndef GTEST_INTERNAL_HAS_STD_SPAN
2419
2432
#define GTEST_INTERNAL_HAS_STD_SPAN 0
@@ -2430,8 +2443,9 @@ using StringView = ::absl::string_view;
2430
2443
} // namespace internal
2431
2444
} // namespace testing
2432
2445
#else
2433
- #ifdef __has_include
2434
- #if __has_include(<string_view>) && GTEST_INTERNAL_CPLUSPLUS_LANG >= 201703L
2446
+ #if defined(__cpp_lib_string_view) || \
2447
+ (GTEST_INTERNAL_HAS_INCLUDE(<string_view>) && \
2448
+ GTEST_INTERNAL_CPLUSPLUS_LANG >= 201703L )
2435
2449
// Otherwise for C++17 and higher use std::string_view for Matcher<>
2436
2450
// specializations.
2437
2451
#define GTEST_INTERNAL_HAS_STRING_VIEW 1
@@ -2443,9 +2457,7 @@ using StringView = ::std::string_view;
2443
2457
} // namespace testing
2444
2458
// The case where absl is configured NOT to alias std::string_view is not
2445
2459
// supported.
2446
- #endif // __has_include(<string_view>) && GTEST_INTERNAL_CPLUSPLUS_LANG >=
2447
- // 201703L
2448
- #endif // __has_include
2460
+ #endif // __cpp_lib_string_view
2449
2461
#endif // GTEST_HAS_ABSL
2450
2462
2451
2463
#ifndef GTEST_INTERNAL_HAS_STRING_VIEW
@@ -2464,8 +2476,8 @@ using Variant = ::absl::variant<T...>;
2464
2476
} // namespace internal
2465
2477
} // namespace testing
2466
2478
#else
2467
- #ifdef __has_include
2468
- # if __has_include(<variant>) && GTEST_INTERNAL_CPLUSPLUS_LANG >= 201703L
2479
+ #if defined(__cpp_lib_variant) || (GTEST_INTERNAL_HAS_INCLUDE(<variant>) && \
2480
+ GTEST_INTERNAL_CPLUSPLUS_LANG >= 201703L )
2469
2481
// Otherwise for C++17 and higher use std::variant for UniversalPrinter<>
2470
2482
// specializations.
2471
2483
#define GTEST_INTERNAL_HAS_VARIANT 1
@@ -2477,16 +2489,16 @@ using Variant = ::std::variant<T...>;
2477
2489
} // namespace internal
2478
2490
} // namespace testing
2479
2491
// The case where absl is configured NOT to alias std::variant is not supported.
2480
- #endif // __has_include(<variant>) && GTEST_INTERNAL_CPLUSPLUS_LANG >= 201703L
2481
- #endif // __has_include
2492
+ #endif // __cpp_lib_variant
2482
2493
#endif // GTEST_HAS_ABSL
2483
2494
2484
2495
#ifndef GTEST_INTERNAL_HAS_VARIANT
2485
2496
#define GTEST_INTERNAL_HAS_VARIANT 0
2486
2497
#endif
2487
2498
2488
- #if defined(GTEST_INTERNAL_CPLUSPLUS_LANG) && \
2489
- GTEST_INTERNAL_CPLUSPLUS_LANG < 201703L
2499
+ #if (defined(__cpp_constexpr) && !defined(__cpp_inline_variables)) || \
2500
+ (defined(GTEST_INTERNAL_CPLUSPLUS_LANG) && \
2501
+ GTEST_INTERNAL_CPLUSPLUS_LANG < 201703L )
2490
2502
#define GTEST_INTERNAL_NEED_REDUNDANT_CONSTEXPR_DECL 1
2491
2503
#endif
2492
2504
0 commit comments