Use GTEST_INTERNAL_CPLUSPLUS_LANG instead of __cplusplus

Some versions of MSVC provide incorrect values for the latter and rely on _MSVC_LANG instead.
Fixes #4226.

PiperOrigin-RevId: 527919195
Change-Id: Ifcca4612074f5ebc5337094426866a187f79f90a
This commit is contained in:
Dino Radakovic 2023-04-28 10:15:31 -07:00 committed by Copybara-Service
parent 0bdaac5a14
commit 797b0ad2a3
3 changed files with 14 additions and 10 deletions

View File

@ -48,6 +48,7 @@
#include "gmock/internal/gmock-port.h" #include "gmock/internal/gmock-port.h"
#include "gtest/gtest-spi.h" #include "gtest/gtest-spi.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "gtest/internal/gtest-port.h"
// Silence C4100 (unreferenced formal parameter) and C4503 (decorated name // Silence C4100 (unreferenced formal parameter) and C4503 (decorated name
// length exceeded) for MSVC. // length exceeded) for MSVC.
@ -221,7 +222,8 @@ TEST(TypeTraits, IsInvocableRV) {
// In C++17 and above, where it's guaranteed that functions can return // In C++17 and above, where it's guaranteed that functions can return
// non-moveable objects, everything should work fine for non-moveable rsult // non-moveable objects, everything should work fine for non-moveable rsult
// types too. // types too.
#if defined(__cplusplus) && __cplusplus >= 201703L #if defined(GTEST_INTERNAL_CPLUSPLUS_LANG) && \
GTEST_INTERNAL_CPLUSPLUS_LANG >= 201703L
{ {
struct NonMoveable { struct NonMoveable {
NonMoveable() = default; NonMoveable() = default;

View File

@ -804,7 +804,8 @@ TEST(ExpectCallTest, InfersCardinality1WhenThereIsWillRepeatedly) {
"to be called at least once"); "to be called at least once");
} }
#if defined(__cplusplus) && __cplusplus >= 201703L #if defined(GTEST_INTERNAL_CPLUSPLUS_LANG) && \
GTEST_INTERNAL_CPLUSPLUS_LANG >= 201703L
// It should be possible to return a non-moveable type from a mock action in // It should be possible to return a non-moveable type from a mock action in
// C++17 and above, where it's guaranteed that such a type can be initialized // C++17 and above, where it's guaranteed that such a type can be initialized

View File

@ -2398,7 +2398,7 @@ using Any = ::absl::any;
} // namespace testing } // namespace testing
#else #else
#ifdef __has_include #ifdef __has_include
#if __has_include(<any>) && __cplusplus >= 201703L && \ #if __has_include(<any>) && GTEST_INTERNAL_CPLUSPLUS_LANG >= 201703L && \
(!defined(_MSC_VER) || GTEST_HAS_RTTI) (!defined(_MSC_VER) || GTEST_HAS_RTTI)
// Otherwise for C++17 and higher use std::any for UniversalPrinter<> // Otherwise for C++17 and higher use std::any for UniversalPrinter<>
// specializations. // specializations.
@ -2411,7 +2411,7 @@ using Any = ::std::any;
} // namespace testing } // namespace testing
// The case where absl is configured NOT to alias std::any is not // The case where absl is configured NOT to alias std::any is not
// supported. // supported.
#endif // __has_include(<any>) && __cplusplus >= 201703L #endif // __has_include(<any>) && GTEST_INTERNAL_CPLUSPLUS_LANG >= 201703L
#endif // __has_include #endif // __has_include
#endif // GTEST_HAS_ABSL #endif // GTEST_HAS_ABSL
@ -2433,7 +2433,7 @@ inline ::absl::nullopt_t Nullopt() { return ::absl::nullopt; }
} // namespace testing } // namespace testing
#else #else
#ifdef __has_include #ifdef __has_include
#if __has_include(<optional>) && __cplusplus >= 201703L #if __has_include(<optional>) && GTEST_INTERNAL_CPLUSPLUS_LANG >= 201703L
// Otherwise for C++17 and higher use std::optional for UniversalPrinter<> // Otherwise for C++17 and higher use std::optional for UniversalPrinter<>
// specializations. // specializations.
#define GTEST_INTERNAL_HAS_OPTIONAL 1 #define GTEST_INTERNAL_HAS_OPTIONAL 1
@ -2447,7 +2447,7 @@ inline ::std::nullopt_t Nullopt() { return ::std::nullopt; }
} // namespace testing } // namespace testing
// The case where absl is configured NOT to alias std::optional is not // The case where absl is configured NOT to alias std::optional is not
// supported. // supported.
#endif // __has_include(<optional>) && __cplusplus >= 201703L #endif // __has_include(<optional>) && GTEST_INTERNAL_CPLUSPLUS_LANG >= 201703L
#endif // __has_include #endif // __has_include
#endif // GTEST_HAS_ABSL #endif // GTEST_HAS_ABSL
@ -2467,7 +2467,7 @@ using StringView = ::absl::string_view;
} // namespace testing } // namespace testing
#else #else
#ifdef __has_include #ifdef __has_include
#if __has_include(<string_view>) && __cplusplus >= 201703L #if __has_include(<string_view>) && GTEST_INTERNAL_CPLUSPLUS_LANG >= 201703L
// Otherwise for C++17 and higher use std::string_view for Matcher<> // Otherwise for C++17 and higher use std::string_view for Matcher<>
// specializations. // specializations.
#define GTEST_INTERNAL_HAS_STRING_VIEW 1 #define GTEST_INTERNAL_HAS_STRING_VIEW 1
@ -2479,7 +2479,8 @@ using StringView = ::std::string_view;
} // namespace testing } // namespace testing
// The case where absl is configured NOT to alias std::string_view is not // The case where absl is configured NOT to alias std::string_view is not
// supported. // supported.
#endif // __has_include(<string_view>) && __cplusplus >= 201703L #endif // __has_include(<string_view>) && GTEST_INTERNAL_CPLUSPLUS_LANG >=
// 201703L
#endif // __has_include #endif // __has_include
#endif // GTEST_HAS_ABSL #endif // GTEST_HAS_ABSL
@ -2500,7 +2501,7 @@ using Variant = ::absl::variant<T...>;
} // namespace testing } // namespace testing
#else #else
#ifdef __has_include #ifdef __has_include
#if __has_include(<variant>) && __cplusplus >= 201703L #if __has_include(<variant>) && GTEST_INTERNAL_CPLUSPLUS_LANG >= 201703L
// Otherwise for C++17 and higher use std::variant for UniversalPrinter<> // Otherwise for C++17 and higher use std::variant for UniversalPrinter<>
// specializations. // specializations.
#define GTEST_INTERNAL_HAS_VARIANT 1 #define GTEST_INTERNAL_HAS_VARIANT 1
@ -2512,7 +2513,7 @@ using Variant = ::std::variant<T...>;
} // namespace internal } // namespace internal
} // namespace testing } // namespace testing
// The case where absl is configured NOT to alias std::variant is not supported. // The case where absl is configured NOT to alias std::variant is not supported.
#endif // __has_include(<variant>) && __cplusplus >= 201703L #endif // __has_include(<variant>) && GTEST_INTERNAL_CPLUSPLUS_LANG >= 201703L
#endif // __has_include #endif // __has_include
#endif // GTEST_HAS_ABSL #endif // GTEST_HAS_ABSL